Arbitrary deadlines change what dates mean and thus how timestamps are processed and stored internally.
Short story: we’ve added daystamp
to the API output for a datapoint and you should just use that if you want to be lazy and agree with Beeminder. Daystamp is a string representation of a date "YYYYMMDD"
. Depending on the deadline, this may not correspond to the calendar date of the timestamp. So confuse!
-
If you give us a date we use that date and pick a timestamp which maps to that date, and is just under the wire for your deadline.
— e.g. If you enter data from the data entry form on the website, or enter a string like8 140
in the advanced or quick entry. -
If you give us a timestamp we use that timestamp and and map it to a date using your timezone and deadline for the goal.
— e.g. if you pass in a timestamp through the API, data from an autodata goal, or actually using the ^ shortcut.
To convert a timestamp to a daystamp, given a timestamp ts
, a deadline d
in seconds, and a timezone tz
:
Time.at(ts - d).in_time_zone(tz)
To pick a timestamp for a given daystamp ds
, a deadline d
in seconds, and a timezone tz
:
Time.use_zone(tz){ Time.zone.parse(ds).end_of_day.to_i + d }
(These snippets are ruby code, and rely on Rails’ ActiveSupport::TimeWithZone.)
Clear as mud? Please discuss.