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. This is used for some of the primary key ids. To prevent violation of the uniqueness constraint, sleep is called for 1 millisecond.

# File lib/anki_record/helpers/time_helper.rb, line 16
def milliseconds_since_epoch
  sleep 0.001
  DateTime.now.strftime("%Q").to_i
end

seconds_since_epoch()

Returns approximately the number of seconds since the 1970 epoch.

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