Skip to Content Skip to Search

Helper module to calculate integer time values since the 1970 epoch.

Specifically, the time that has passed since 00:00:00 UTC Jan 1 1970.

Methods
M
S

Instance Public methods

milliseconds_since_epoch()

Returns approximately the number of milliseconds since the 1970 epoch. A random amount of milliseconds between -5000 and 5000 is added so that primary key ids calculated with this should be unique.

# File lib/anki_record/helpers/time_helper.rb, line 15
def milliseconds_since_epoch
  DateTime.now.strftime("%Q").to_i + rand(-5000..5000)
end

seconds_since_epoch()

Returns approximately the number of seconds since the 1970 epoch.

# File lib/anki_record/helpers/time_helper.rb, line 21
def seconds_since_epoch
  Time.now.to_i
end