Class: Hijri::DateTime

Inherits:
Date
  • Object
show all
Defined in:
lib/hijri/format.rb,
lib/hijri/datetime.rb

Constant Summary

Constants inherited from Date

Hijri::Date::ABBR_DAYNAMES, Hijri::Date::ABBR_MONTHNAMES, Hijri::Date::DAYNAMES, Hijri::Date::HALF_DAYS_IN_DAY, Hijri::Date::HOURS_IN_DAY, Hijri::Date::MILLISECONDS_IN_DAY, Hijri::Date::MILLISECONDS_IN_SECOND, Hijri::Date::MINUTES_IN_DAY, Hijri::Date::MONTHNAMES, Hijri::Date::NANOSECONDS_IN_DAY, Hijri::Date::NANOSECONDS_IN_SECOND, Hijri::Date::SECONDS_IN_DAY

Instance Attribute Summary collapse

Attributes inherited from Date

#day, #month, #year

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Date

#<=>, _httpdate, _iso8601, _jisx0301, _parse, _rfc2822, _rfc3339, _xmlschema, #asctime, #httpdate, #islamic_leap_year?, #last_day_of_islamic_month, #rfc2822, #to_abs, #to_hijri, today, #wday, #weeknum, #yday

Constructor Details

#initialize(year = 1, month = 1, day = 1, hour = 0, minute = 0, second = 0, zone = "00:00") ⇒ DateTime

Returns a new instance of DateTime.



10
11
12
13
14
15
16
17
# File 'lib/hijri/datetime.rb', line 10

def initialize(year=1, month=1, day=1, hour=0, minute=0, second=0, zone="00:00")
  super(year, month, day)
  @hour   = hour
  @minute = minute
  @second = second
  @offset = zone.to_f / 24
  @zone   = zone
end

Instance Attribute Details

#hourObject (readonly)

Returns the value of attribute hour.



4
5
6
# File 'lib/hijri/datetime.rb', line 4

def hour
  @hour
end

#minuteObject (readonly) Also known as: min

Returns the value of attribute minute.



4
5
6
# File 'lib/hijri/datetime.rb', line 4

def minute
  @minute
end

#offsetObject (readonly)

Returns the value of attribute offset.



4
5
6
# File 'lib/hijri/datetime.rb', line 4

def offset
  @offset
end

#secondObject (readonly) Also known as: sec

Returns the value of attribute second.



4
5
6
# File 'lib/hijri/datetime.rb', line 4

def second
  @second
end

#zoneObject (readonly)

Returns the value of attribute zone.



4
5
6
# File 'lib/hijri/datetime.rb', line 4

def zone
  @zone
end

Class Method Details

._strptime(str, fmt = '%FT%T%z') ⇒ Object



1281
1282
1283
# File 'lib/hijri/format.rb', line 1281

def self._strptime(str, fmt='%FT%T%z')
  super(str, fmt)
end

.nowObject



36
37
38
39
40
41
# File 'lib/hijri/datetime.rb', line 36

def now
  datetime = ::DateTime.now
  hijri = datetime.to_hijri
  hijri.change :hour => datetime.hour, :minute => datetime.minute, :second => datetime.second
  hijri
end

Instance Method Details

#change(kargs) ⇒ Object



19
20
21
22
23
24
# File 'lib/hijri/datetime.rb', line 19

def change(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) ⇒ Object



1297
1298
1299
# File 'lib/hijri/format.rb', line 1297

def iso8601(n=0)
  super() + iso8601_timediv(n)
end

#jisx0301(n = 0) ⇒ Object



1305
1306
1307
# File 'lib/hijri/format.rb', line 1305

def jisx0301(n=0)
  super() + iso8601_timediv(n)
end

#rfc3339(n = 0) ⇒ Object



1301
# File 'lib/hijri/format.rb', line 1301

def rfc3339(n=0) iso8601(n) end

#strftime(fmt = '%FT%T%:z') ⇒ Object



1277
1278
1279
# File 'lib/hijri/format.rb', line 1277

def strftime(fmt='%FT%T%:z')
  super(fmt)
end

#to_greoObject



26
27
28
# File 'lib/hijri/datetime.rb', line 26

def to_greo
  ::DateTime.new *Converter.hijri_to_greo(self)
end

#to_sObject



30
31
32
33
# File 'lib/hijri/datetime.rb', line 30

def to_s
  zone_str = (@zone == '00:00' ? "+#{@zone}" : @zone)
  "#{super}T#{sprintf('%02d', @hour)}:#{sprintf('%02d', @minute)}:#{sprintf('%02d', @second)}#{zone_str}"
end

#xmlschema(n = 0) ⇒ Object

:nodoc:



1303
# File 'lib/hijri/format.rb', line 1303

def xmlschema(n=0) iso8601(n) end