Class: Origami::Date

Inherits:
ByteString show all
Defined in:
lib/origami/string.rb

Overview

Class representing a Date string. _Not used_ _Not tested_

Constant Summary collapse

REGEXP_TOKEN =

:nodoc:

"(D:)?(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(?:([\\+-Z])(?:(\\d{2})')?(?:(\\d{2})')?)?"

Constants inherited from ByteString

ByteString::TOKENS

Constants included from Object

Object::TOKENS

Instance Attribute Summary

Attributes included from String

#encoding

Attributes included from Object

#file_offset, #generation, #no, #objstm_offset, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ByteString

#expand, #to_hex, #to_obfuscated_str, #to_s, #value

Methods included from String

#infer_encoding, #real_type, #to_pdfdoc, #to_utf16be, #to_utf8

Methods included from Object

#<=>, #copy, #indirect_parent, #is_indirect?, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #xrefs

Methods inherited from String

#is_binary_data?, #to_o

Constructor Details

#initialize(year, month = nil, day = nil, hour = nil, minute = nil, second = nil, ut_sign = nil, ut_hours = nil, ut_min = nil) ⇒ Date

Returns a new instance of Date.



365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/origami/string.rb', line 365

def initialize(year, month = nil, day = nil, hour = nil, minute = nil, second = nil, ut_sign = nil, ut_hours = nil, ut_min = nil)

  year_str = '%04d' % year
  month_str = month.nil? ? '01' : '%02d' % month
  day_str = day.nil? ? '01' : '%02d' % day 
  hour_str = '%02d' % hour
  minute_str = '%02d' % minute
  second_str = '%02d' % second
  
  date_str = "D:#{year_str}#{month_str}#{day_str}#{hour_str}#{minute_str}#{second_str}"
  date_str << "#{ut_sign}#{'%02d' % ut_hours}'#{'%02d' % ut_min}" unless ut_sign.nil?

  super(date_str)
end

Class Method Details

.nowObject

Returns current Date String in UTC time.



402
403
404
405
406
407
408
409
410
411
412
# File 'lib/origami/string.rb', line 402

def self.now
  now = Time.now.getutc
  year  = now.strftime("%Y").to_i
  month = now.strftime("%m").to_i
  day   = now.strftime("%d").to_i
  hour  = now.strftime("%H").to_i
  min   = now.strftime("%M").to_i
  sec   = now.strftime("%S").to_i

  Origami::Date.new(year, month, day, hour, min, sec, 'Z', 0, 0)
end

.parse(stream) ⇒ Object

:nodoc:

Raises:

  • (InvalidDate)


380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/origami/string.rb', line 380

def self.parse(stream) #:nodoc:
  
  dateReg = Regexp.new(REGEXP_TOKEN)
  
  raise InvalidDate if stream.scan(dateReg).nil?
    
  year  = stream[2].to_i
  month = stream[3] and stream[3].to_i
  day   = stream[4] and stream[4].to_i
  hour  = stream[5] and stream[5].to_i
  min   = stream[6] and stream[6].to_i
  sec   = stream[7] and stream[7].to_i
  ut_sign   = stream[8]
  ut_hours  = stream[9] and stream[9].to_i
  ut_min    = stream[10] and stream[10].to_i
    
  Origami::Date.new(year, month, day, hour, min, sec, ut_sign, ut_hours, ut_min)
end