class Hijri::DateTime
Attributes
hour[R]
min[R]
minute[R]
offset[R]
sec[R]
second[R]
zone[R]
Public Class Methods
_strptime(str, fmt='%FT%T%z')
click to toggle source
Calls superclass method
Hijri::Date::_strptime
# File lib/hijri/format.rb, line 1281 def self._strptime(str, fmt='%FT%T%z') super(str, fmt) end
new(year=1, month=1, day=1, hour=0, minute=0, second=0, zone="00:00")
click to toggle source
Calls superclass method
Hijri::Date::new
# File lib/hijri/datetime.rb, line 9 def initialize(year=1, month=1, day=1, hour=0, minute=0, second=0, zone="00:00") super(year, month, day) if valid_time?(hour, minute, second, zone) @hour = hour @minute = minute @second = second @offset = zone.to_f / 24 @zone = zone else raise ArgumentError, "Invalid Date" end end
now()
click to toggle source
# File lib/hijri/datetime.rb, line 48 def now datetime = ::DateTime.now hijri = datetime.to_hijri hijri.change :hour => datetime.hour, :minute => datetime.minute, :second => datetime.second hijri end
Public Instance Methods
change(kargs)
click to toggle source
Calls superclass method
Hijri::Date#change
# File lib/hijri/datetime.rb, line 22 def change(kargs) super(kargs) @hour = kargs.fetch :hour, hour @minute = kargs.fetch :minute, minute @second = kargs.fetch :second, second @zone = kargs.fetch :zone, zone end
iso8601(n=0)
click to toggle source
Calls superclass method
Hijri::Date#iso8601
# File lib/hijri/format.rb, line 1297 def iso8601(n=0) super() + iso8601_timediv(n) end
jisx0301(n=0)
click to toggle source
Calls superclass method
Hijri::Date#jisx0301
# File lib/hijri/format.rb, line 1305 def jisx0301(n=0) super() + iso8601_timediv(n) end
rfc3339(n=0)
click to toggle source
# File lib/hijri/format.rb, line 1301 def rfc3339(n=0) iso8601(n) end
strftime(fmt='%FT%T%:z')
click to toggle source
Calls superclass method
Hijri::Date#strftime
# File lib/hijri/format.rb, line 1277 def strftime(fmt='%FT%T%:z') super(fmt) end
to_greo()
click to toggle source
# File lib/hijri/datetime.rb, line 30 def to_greo ::DateTime.new *Converter.hijri_to_greo(self) end
to_s()
click to toggle source
# File lib/hijri/datetime.rb, line 34 def to_s zone_str = (@zone == '00:00' ? "+#{@zone}" : @zone) format('%.4d-%02d-%02dT%02d:%02d:%02d%s', year, mon, mday, hour, min, sec, zone_str) end
valid_time?(hour, minute, second, zone)
click to toggle source
# File lib/hijri/datetime.rb, line 40 def valid_time?(hour, minute, second, zone) return false unless (0..23).cover?(hour) return false unless (0..59).cover?(minute) return false unless (0..59).cover?(second) return true end