Class: Origami::Date
- Inherits:
-
ByteString
- Object
- String
- ByteString
- Origami::Date
- 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
Constants included from Object
Instance Attribute Summary
Attributes included from String
Attributes included from Object
#file_offset, #generation, #no, #objstm_offset, #parent
Class Method Summary collapse
-
.now ⇒ Object
Returns current Date String in UTC time.
-
.parse(stream, parser = nil) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(year, month = nil, day = nil, hour = nil, minute = nil, second = nil, ut_sign = nil, ut_hours = nil, ut_min = nil) ⇒ Date
constructor
A new instance of Date.
Methods inherited from ByteString
#expand, #to_hex, #to_obfuscated_str, #to_s, #value
Methods included from String
included, #infer_encoding, native_type, #to_pdfdoc, #to_utf16be, #to_utf8
Methods included from Object
#<=>, #cast_to, #copy, #export, #indirect_parent, #is_indirect?, #logicalize, #logicalize!, native_type, #native_type, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #resolve_all_references, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #xrefs
Methods inherited from String
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.
382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/origami/string.rb', line 382 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
.now ⇒ Object
Returns current Date String in UTC time.
419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/origami/string.rb', line 419 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, parser = nil) ⇒ Object
:nodoc:
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/origami/string.rb', line 397 def self.parse(stream, parser = nil) #: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 |