[フレーム]

Class: DateTime

Inherits:
Date show all
Defined in:
opal/stdlib/date/date_time.rb,
opal/stdlib/date/formatters.rb

Constant Summary

Constants inherited from Date

Date::ABBR_DAYNAMES , Date::ABBR_MONTHNAMES , Date::DAYNAMES , Date::ENGLAND , Date::GREGORIAN , Date::ITALY , Date::JULIAN , Date::MONTHNAMES

Instance Attribute Summary

Attributes inherited from Date

#start

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Date

#<< , #<=> , #>> , _days_in_month , #as_json , #clone , #cwday , #cweek , def_formatter , #downto , gregorian_leap? , #jd , #julian? , #new_start , #next , #next_day , #next_month , #next_year , #prev_day , #prev_month , #prev_year , #step , #strftime , #to_json , #to_n , today , #upto , wrap

Methods included from Forwardable

#def_instance_delegator , #def_instance_delegators , #instance_delegate

Constructor Details

#initialize(year = -4712,, month = 1, day = 1, hours = 0, minutes = 0, seconds = 0, offset = 0, start = ITALY) ⇒ DateTime

Returns a new instance of DateTime.

12
13
14
15
16
17
18
19
20
21
22
23
# File 'opal/stdlib/date/date_time.rb', line 12
def initialize(year = -4712, month = 1, day = 1, hours = 0, minutes = 0, seconds = 0, offset = 0, start = ITALY )
 %x{
 // Because of Gregorian reform calendar goes from 1582年10月04日 to 1582年10月15日.
 // All days in between end up as 4 october.
 if (year === 1582 && month === 10 && day > 4 && day < 15) {
 day = 4;
 }
 }
 @date = Time .new(year, month, day, hours, minutes, seconds, offset)
 @start = start
end

Class Method Details

.nowObject

3
4
5
# File 'opal/stdlib/date/date_time.rb', line 3
def now
 wrap Time .now
end

.parse(str) ⇒ Object

7
8
9
# File 'opal/stdlib/date/date_time.rb', line 7
def parse(str)
 wrap Time .parse (str)
end

Instance Method Details

#+(other) ⇒ Object

39
40
41
# File 'opal/stdlib/date/date_time.rb', line 39
def +(other)
 ::DateTime .wrap  @date + other
end

#-(other) ⇒ Object

43
44
45
46
47
48
49
50
51
# File 'opal/stdlib/date/date_time.rb', line 43
def -(other)
 `if (Opal.is_a(other, #{::Date })) other = other.date`
 result = @date - other
 if result.is_a? ::Time 
 ::DateTime .wrap  result
 else
 result
 end
end

#new_offset(offset) ⇒ Object

53
54
55
56
57
58
# File 'opal/stdlib/date/date_time.rb', line 53
def new_offset(offset)
 new_date = clone
 offset = Time ._parse_offset(offset)
 `new_date.date.timezone = offset`
 new_date
end

#offsetObject

35
36
37
# File 'opal/stdlib/date/date_time.rb', line 35
def offset
 @date.gmt_offset / (24 * 3600r)
end

#sec_fractionObject Also known as: second_fraction

29
30
31
# File 'opal/stdlib/date/date_time.rb', line 29
def sec_fraction
 @date.usec / 1_000_000r
end

#to_dateObject

68
69
70
# File 'opal/stdlib/date/date_time.rb', line 68
def to_date
 Date .new (year, month, day)
end

#to_datetimeObject

60
61
62
# File 'opal/stdlib/date/date_time.rb', line 60
def to_datetime
 self
end

#to_timeObject

64
65
66
# File 'opal/stdlib/date/date_time.rb', line 64
def to_time
 @date.dup
end

AltStyle によって変換されたページ (->オリジナル) /