Skip to content

Instantly share code, notes, and snippets.

@lmaccherone
lmaccherone / Working-with-Dates-Times-and-Timezones-Top-10-Tips-for-Developers.markdown
Last active May 29, 2018 23:15
What's the correct query clause to get all the transactions from March on the east coast of the US? The correct answer is `"2012-03-01T05" <= eventTimestamp < "2012-04-01T04"`. Notice how the timeshift for the beginning of March is different from the end. Getting this right is mind bendingly difficult. This blog post and the Lumenize/tzTime libr…

Working with Dates, Times, and Timezones

Top 10 recommendations for developers

Update: tzTime (documentation) is now available seperately from Lumenize. The examples below still work because tzTime is a dependency of Lumenize and included in that package (as well as Rally's App SDK v2.0p6 or greater). However, Lumenize includes a lot more functionality around time-series and temporal model aggregations, OLAP Cube, etc. If you just want the Time object, just grab tzTime.

What's the correct query clause to get all the transactions from March? The naive answer is "2012-03-01" &lt;= eventTimestamp &lt;= "2012-03-31" but what if the person worked in the eastern US and wanted timezone taken into account? Then the correct answer is "2012-03-01T05" &lt;= eventTimestamp &lt; "2012-04-01T04". Notice how the timeshift for the beginning of March is different from the end. Getting this right is mind bendingly di