|
| 1 | +# dummy |
| 2 | + |
| 3 | +## MoonScript-specific instructions |
| 4 | + |
| 5 | +The input and expected datetime strings in the tests are expressed in the UTC timezone. |
| 6 | +This is done to remove the effects of daylight saving time in your local timezone. |
| 7 | + |
| 8 | +The key challenge in this exercise is to parse the input timestamp _as if you are in the UTC timezone_. |
| 9 | +Lua's builtin `os.time` function simply can't do that. |
| 10 | +It can only return the **local** time. |
| 11 | +And it's not as simple as adjusting that local time with your timezone offset (in seconds) from UTC: |
| 12 | +you need to know the offset _at the moment you are parsing_, not the _current_ offset. |
| 13 | + |
| 14 | +Datetime arithmetic is a **very** complicated topic, and you don't want to have to re-invent that wheel: you want to be able to rely on a well-tested library to get the details right. |
| 15 | + |
| 16 | +The `lua-tz` module works well for this exercise. |
| 17 | +It provides `tz.time` and `tz.date` functions that are drop-in replacements for the builtin `os.time` and `os.date` functions, but allow you to provide a timezone name as an extra parameter. |
| 18 | + |
| 19 | +We have provided some additional datetime modules to the MoonScript test runner, if you want to experiment with them. |
| 20 | + |
| 21 | +* `lua-tz`: [luarocks info page][lua-tz-rock], [website][lua-tz-home], [documentation][lua-tz-doc] |
| 22 | +* `date`: [luarocks info page][date-rock], [website][date-home], [documentation][date-doc] |
| 23 | +* `luatz`: [luarocks info page][luatz-rock], [website][luatz-home], [documentation][luatz-doc] |
| 24 | + |
| 25 | +[lua-tz-rock]: https://luarocks.org/modules/anaef/lua-tz |
| 26 | +[lua-tz-home]: https://github.com/anaef/lua-tz#readme |
| 27 | +[lua-tz-doc]: https://github.com/anaef/lua-tz/tree/master/doc#readme |
| 28 | +[date-rock]: https://luarocks.org/modules/tieske/date |
| 29 | +[date-home]: https://github.com/Tieske/date#readme |
| 30 | +[date-doc]: https://tieske.github.io/date/ |
| 31 | +[luatz-rock]: https://luarocks.org/modules/daurnimator/luatz |
| 32 | +[luatz-home]: https://github.com/daurnimator/luatz#readme |
| 33 | +[luatz-doc]: https://daurnimator.github.io/luatz/ |
0 commit comments