What I learned today — 12 January 2018
Wrapping up the main theme of this week, today I saw clearly the importance of being consistent when dealing with local versus UTC dates. This is quite an obvious one, but easy to get wrong.
More specifically, I learned that by default MomentJS does everything in the local time, unless otherwise instructed. This includes parsing dates that don’t indicate whether they are UTC dates, offset dates, or time zoned dates. Instruct MomentJS to parse a date as UTC using moment.utc()
, for example (using Typescript):
const utcToday = moment.utc('2018-01-12', 'YYYY-MM-DD');
Besides this I also had fun on the back end with Java Time API, parsing MonthDay
objects (the expected format is --MM-DD
) and converting LocalDate
to MonthDay
(MonthDay.from(localDate)
), and MonthDay
to LocalDate
in the current year (LocalDate.now().with(monthDay)
).