Class: Oinky::Internal::OinkyDateTime
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- Oinky::Internal::OinkyDateTime
- Defined in:
- lib/oinky.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dt(dt) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/oinky.rb', line 165 def self.from_dt(dt) dt = dt.new_offset(0) unpacked = OinkyUnpackedDateTime.new unpacked[:years_since_1900] = dt.year - 1900 unpacked[:months_since_january] = dt.month - 1 unpacked[:days_since_first_of_month] = dt.day - 1 unpacked[:hours_since_midnight] = dt.hour unpacked[:minutes_since_hour] = dt.minute unpacked[:seconds_since_minute] = dt.second unpacked[:microseconds_since_second] = (dt.second_fraction * 1000000).to_i v = OinkyDateTime.new Internal.wrap_oinky(Internal.nky_pack_datetime(v, unpacked)) v end |
.from_intval(intval) ⇒ Object
157 158 159 160 161 |
# File 'lib/oinky.rb', line 157 def self.from_intval(intval) v = OinkyDateTime.new v[:ptime] = intval v end |
.parse(str) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/oinky.rb', line 150 def self.parse(str) # This can be a ruby string or a native string. This method # doesn't take a reference. #puts "parsing: " + str dt = DateTime.parse(str.to_s) return from_dt(dt) end |
Instance Method Details
#intval ⇒ Object
162 163 164 |
# File 'lib/oinky.rb', line 162 def intval self[:ptime] end |
#rb_val ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/oinky.rb', line 181 def rb_val unpacked = OinkyUnpackedDateTime.new Internal.wrap_oinky(Internal.nky_unpack_datetime(self, unpacked)) # Make a datetime, accounting for sloppy encoding with overlapping # months and days dt = DateTime. new(1900 + unpacked[:years_since_1900]). next_month(unpacked[:months_since_january]). next_day(unpacked[:days_since_first_of_month]) daypart = ((((((unpacked[:hours_since_midnight] * 60) + unpacked[:minutes_since_hour]) * 60) + unpacked[:seconds_since_minute]) * 1000000) + unpacked[:microseconds_since_second]).quo(3600000000 * 24) return dt + daypart end |
#to_datetime ⇒ Object
199 200 201 |
# File 'lib/oinky.rb', line 199 def to_datetime rb_val end |