Class: Hijri::DateTime

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

Constant Summary

Constants inherited from Date

Hijri::Date::DAYNAMES, Hijri::Date::MONTHNAMES_EN

Instance Attribute Summary collapse

Attributes inherited from Date

#day, #month, #year

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Date

#islamic_leap_year?, #last_day_of_islamic_month, #to_abs, #to_s, today

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.



5
6
7
8
9
10
11
# File 'lib/hijri/datetime.rb', line 5

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
  @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)

Returns the value of attribute minute.



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

def minute
  @minute
end

#secondObject (readonly)

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

.nowObject



27
28
29
30
31
32
# File 'lib/hijri/datetime.rb', line 27

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



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

def change(kargs)
  @hour   = kargs.fetch :hour, hour
  @minute = kargs.fetch :minute, minute
  @second = kargs.fetch :second, second
  @zone   = kargs.fetch :zone, zone
end

#to_greoObject



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

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