As a Roblox developer, it is currently too hard to obtain time zone and week information when using DateTime format strings. DateTime is missing some crucial elemental tokens for date information that would help with features like LiveOps. I need to use workarounds or other API for this such as os.date which provides a wider range of options.
If Roblox is able to address this issue, it would improve my development experience because I could fully use DateTime to my advantage in order to create periodic data identifiers and in-experience timers that accurately tell the end user when they can expect an event to occur in their time zone. I would not need to mix other APIs because DateTime alone would provide what I need.
Consider that os.date offers the following formatting strings that DateTime does not:
- Week number of the year (important for creating time-based identifiers for periodic data)
- ISO 8601 UTC offset (important for FormatLocalTime use cases)
- Time zone name and/or abbreviation (important for FormatLocalTime use cases)
Without these elemental tokens, I need to make best case assumptions in order to retrieve this information: for time zone I need to assume the time zone from the system locale and for week of the year I need to check in with the day of the year (token DDD).
Providing these elemental tokens would rid the need for me to use workarounds or to rely on os.date which is arguably inferior for date parsing over DateTime and has caused me trouble in the past when performing local tests (os.date is incapable of working in UTC when using the format string unless you use the special format
!*t to force UTC time).
Compare these examples:
-- This would be the most ideal, but if you use the format string with -- specifiers then you don't have control over key details like the -- timezone. Bad for local testing. local fmt = os.date("%W%Y%Z") -- This is slightly less ideal. It's more code and operations overall; instead -- of directly formatting a string, we need to access components to do it. We -- also cannot fetch timezone or week number this way! local utc = os.date("!*t") local fmt = string.format("%d", utc.year) -- Standard DateTime objects do not have timezone or week number! local dt = DateTime.now():ToUniversalTime() local fmt = string.format("%d", dt.Year) -- Suffers the same problem as using the special UTC format string with os.date, -- there is no token for timezone or week number. local dt = DateTime.new() local fmt = dt:FormatUniversalTime("YYYY", "en-ca") -- What if we could solve all this with a token? Example: local dt = DateTime.new() local fmt = dt:FormatLocalTime("WWYYYYZZZ", SystemLocaleId)