Module: UnixEpoch::InstanceMethods

Included in:
DateTime
Defined in:
lib/unix_epoch.rb

Instance Method Summary collapse

Instance Method Details

#to_iFixnum, Bignum

Converts the current Date & Time into a Fixnum or Bignum representing the Unix Timestamp

Returns:

  • (Fixnum, Bignum)

    unix timestamp



77
78
79
# File 'lib/unix_epoch.rb', line 77

def to_i
    self.to_unix_ts
end

#to_unix_tsFixnum, Bignum

Converts the current Date & Time into a Fixnum or Bignum representing the Unix Timestamp

Returns:

  • (Fixnum, Bignum)

    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