Working with dates and times, especially calculating differences, is always extremely complicated and requires lots spaghetti code.

You have to deal with different time zones (that get re-defined all the time for political shenanigans), daylight "savings" times (different if you cross the equator, different in different countries and redefined for political shenanigans), different calendars altogether (julian, gregorian, japanese, china, north korea, ...) including different times of the year when the year number (or name) changes, leap days, leap seconds, etc...

Tom Scott has a video on YouTube called "The Problem with Time & Timezones" that goes into more details, but, basically, you have to pull in dozens of data files (in different formats, no less) that describe the current and past situations, do a whole lot of complicated parsing and calculations and then you get a result...

...that may not be correct if you schedule an event in the future, because by then a country might have decided to entirely skip a day and/or the IERS(*) might have released a new Bulletin C that adds a 61th second to a specified minute on the last day of March or June or September or December.

Edit: And, oh, if you calculate times from late 1793 to 1805 in France (for with the regions only somewhat match the current borders), please note that they used the French Republican calendar, with 12 months with 30 days each, plus 5 (or 6 in leap years) "extra" days, weeks were 10 days long. And each day had 10 hours with 100 minutes each, each with 100 seconds. And those seconds don't match up in length with the seconds you are probably used to.

Edit 2: Also keep in mind, when daylight savings time starts, the clocks go backwards (usually an hour, could be more, could be less), so usually the same hour repeats in the local time zone. You need to know which version of that hour is the correct one and send out the reminder notification accordingly...

Edit 3: As a side note, did you know that French (and other countries) railways used (past tense, maybe, hopefully) their own time zone(s)? Why French Railway Stations Delayed Their Clocks (& What Happened When They Did).


(*) IERS = International Earth Rotation and Reference Systems Service
PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
Also check out my sisters artwork and my weekly webcomics

In reply to Re: System for calculating timing of reminder messages? by cavac
in thread System for calculating timing of reminder messages? by jest

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.