‹ BackHN Continuity

Thread

Footguns with Postgres “at time zone 'UTC'”

169 points · 114 comments · birdculture

  1. layer8 · · focus · HN ↗
    > Adding a month with + INTERVAL '1 months' is timezone-dependent. […]

    Adding months isn’t well-defined anyway, even when using date, for days of month > 28. I think it’s a mistake that systems generically allow such a computation (as opposed to application code implementing domain-specific business rules).

    1. cryptonector · · focus · HN ↗
      D. Richard Hipp had a great blog about this on sqlite.org quite a while back.
      1. layer8 · · focus · HN ↗
        If you have a link that would be appreciated.
        1. cryptonector · · focus · HN ↗
          Looking... I can&#x27;t find it with Google, but <a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;lang_datefunc.html" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;lang_datefunc.html mentions it:

          | Because the length of a month or year changes from one month or year to the next, ambiguities can arise when shifting a date by months and&#x2F;or years. For example, what is the date one year after 2024-02-29? Is it 2025-02-28 or 2025-03-01? Or what is the date that is two months after 2023-12-31? Is it 2024-02-29 or 2024-03-02? There is no consensus on how to resolve this ambiguity, so the &quot;ceiling&quot; and &quot;floor&quot; modifiers (14 and 15) are available to let the programmer decide. If the next modifier after a time shift is &quot;ceiling&quot;, then any ambiguity in the date is resolved by choosing the later date. The &quot;floor&quot; modifier resolves ambiguities by resolving to the last day of the previous month. The default behavior is &quot;ceiling&quot;.

          1. hulitu · · focus · HN ↗
            &gt; For example, what is the date one year after 2024-02-29?

            2025-03-01

            &gt; Or what is the date that is two months after 2023-12-31? Is it 2024-02-29 or 2024-03-02?

            2024-02-29

            But better use units of fixed size, if you do not want trouble.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.