Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/tt.rb
Constant Summary collapse
- Beginning =
Time.at(0)
- End =
Time.at((2**31)-1)
- Now =
Time.now
- Null =
Time.at(0).instance_eval do def to_s() "" end def inspect() "" end self end
- Parse =
hack to fix Time.parse bug
Time.method 'parse'
Class Method Summary collapse
Instance Method Summary collapse
- #to_date ⇒ Object
- #to_s(n = 0) ⇒ Object (also: #inspect)
- #to_yaml(opts = {}) ⇒ Object
Class Method Details
.parse(string) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/tt.rb', line 105 def self.parse string if string =~ %r'^\d\d\d\d-\d\d-\d\dT\d\d:?$' string = string.sub(%r/:$/,'') + ':00' end if string =~ %r/\ban\b/ string = string.sub(%r/\ban\b/, '1') end if string =~ %r'^\d\d\d\d-\d\d-\d\d' Parse.call string else Chronic.parse string, :context => :past end end |
Instance Method Details
#to_date ⇒ Object
119 120 121 |
# File 'lib/tt.rb', line 119 def to_date Date.new year, month, day end |
#to_s(n = 0) ⇒ Object Also known as: inspect
100 |
# File 'lib/tt.rb', line 100 def to_s(n=0) iso8601(n) end |
#to_yaml(opts = {}) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/tt.rb', line 123 def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| tz = "Z" # from the tidy Tobias Peters <[email protected]> Thanks! unless self.utc? utc_same_instant = self.dup.utc utc_same_writing = Time.utc(year,month,day,hour,min,sec,usec) difference_to_utc = utc_same_writing - utc_same_instant if (difference_to_utc < 0) difference_sign = '-' absolute_difference = -difference_to_utc else difference_sign = '+' absolute_difference = difference_to_utc end difference_minutes = (absolute_difference/60).round tz = "%s%02d:%02d" % [ difference_sign, difference_minutes / 60, difference_minutes % 60] end standard = self.strftime( "%Y-%m-%dT%H:%M:%S" ) standard += ".%02d" % [usec] #if usec.nonzero? standard += "%s" % [tz] if to_yaml_properties.empty? out.scalar( taguri, standard, :plain ) else out.map( taguri, to_yaml_style ) do |map| map.add( 'at', standard ) to_yaml_properties.each do |m| map.add( m, instance_variable_get( m ) ) end end end end end |