Module: UnixEpoch::InstanceMethods
- Included in:
- DateTime
- Defined in:
- lib/unix_epoch.rb
Instance Method Summary collapse
-
#to_i ⇒ Fixnum, Bignum
Converts the current Date & Time into a Fixnum or Bignum representing the Unix Timestamp.
-
#to_unix_ts ⇒ Fixnum, Bignum
Converts the current Date & Time into a Fixnum or Bignum representing the Unix Timestamp.
Instance Method Details
#to_i ⇒ Fixnum, Bignum
Converts the current Date & Time into a Fixnum or Bignum representing the Unix Timestamp
77 78 79 |
# File 'lib/unix_epoch.rb', line 77 def to_i self.to_unix_ts end |
#to_unix_ts ⇒ Fixnum, Bignum
Converts the current Date & Time into a Fixnum or Bignum representing the Unix Timestamp
67 68 69 70 71 72 73 74 |
# File 'lib/unix_epoch.rb', line 67 def to_unix_ts delta_days = self.jd - UnixEpoch.jd_unix_epoch() unix_ts = delta_days * 86_400 h, m, s = self.class.day_fraction_to_time(day_fraction) delta_secs = h * 3600 + m * 60 + s delta_secs -= UnixEpoch.jd_fr_to_secs(offset) if offset != 0 # remove tz offset to get back to UTC unix_ts += delta_secs end |