Module: Matiox::Initializers
- Included in:
- Matiox
- Defined in:
- lib/matiox/initializers/default.rb,
lib/matiox/initializers/from_gregorian.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_iso8601(date) ⇒ Object
13 14 15 |
# File 'lib/matiox/initializers/from_gregorian.rb', line 13 def from_iso8601(date) raise Error::NotYetImplemented end |
.from_ymd(date) ⇒ Object
9 10 11 |
# File 'lib/matiox/initializers/from_gregorian.rb', line 9 def from_ymd(date) raise Error::NotYetImplemented end |
.from_ymdhms(date) ⇒ Object
5 6 7 |
# File 'lib/matiox/initializers/from_gregorian.rb', line 5 def from_ymdhms(date) raise Error::NotYetImplemented end |
Instance Method Details
#initialize(date = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/matiox/initializers/default.rb', line 4 def initialize(date=nil) case date when DateTime @gregorian = date when Time seconds = date.sec + Rational(date.usec, 10**6) offset = Rational(date.utc_offset, 60 * 60 * 24) @gregorian = DateTime.new( date.year, date.month, date.day, date.hour, date.min, seconds, offset ) #de TODO: Move these into their own self.from_ methods and invoke in general initializer here: #de TODO: Use Regular expressions? when String begin @gregorian = DateTime.strptime(date, '%Y-%m-%dT%H:%M:%S%z') rescue begin @gregorian = DateTime.strptime(date, '%Y-%m-%d %H:%M:%S') rescue begin @gregorian = DateTime.strptime(date, '%Y-%m-%d') rescue raise Matiox::Error::GregorianDate::IncorrectlyFormatted.new("Bad date string: #{date}") end end end else @gregorian = DateTime.now end end |