API Changes (aribitrary deadlines and dates)

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 like 8 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.

1 Like

Makes sense to me.

timestamp is a unix timestamp (in seconds)

Is the API able to return information about deadline changes and timezone
changes?

(I can’t think of a use case for them right now, but they might be useful to know.)

1 Like

Not explicitly, but each datapoint stores deadline and tzoffset with it as well, (though we’re not currently including those in API output – only the current deadline with the goal resource). If there were a desire/use for them we could include.

1 Like