Module: AnkiRecord::Helpers::TimeHelper
- Included in:
- Card, Collection, Deck, DeckOptionsGroup, Note, NoteType
- Defined in:
- lib/anki_record/helpers/time_helper.rb
Overview
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.
Instance Method Summary collapse
-
#milliseconds_since_epoch ⇒ Object
Returns approximately the number of milliseconds since the 1970 epoch.
-
#seconds_since_epoch ⇒ Object
Returns approximately the number of seconds since the 1970 epoch.
Instance Method Details
#milliseconds_since_epoch ⇒ Object
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.
16 17 18 19 |
# 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 ⇒ Object
Returns approximately the number of seconds since the 1970 epoch.
23 24 25 |
# File 'lib/anki_record/helpers/time_helper.rb', line 23 def seconds_since_epoch Time.now.to_i end |