[Remind-Fans] Can remind "count" time?

Tim Chase remind at tim.thechases.com
Tue Feb 18 12:33:03 EST 2020


On 2020-02-18 11:36, Sector11 wrote:
> Anyone know if remind can count days to/from ...
> Idea from:
> [ord(year(trigdate())-1977)]
> 
> ↑↑↑↑↑ expand to include #days #months # years

Remind lets you subtract two dates to get the number of days in
between:

  SET retirement date(2040, 4, 1)
  REM MSG Your retirement is [retirement - $U] \
    day[plural(retirement - $U)] away

If you're okay with rough approximations that every year is 365 days,
you can do something like (untested)

  FSET ymd_diff(days) \
    (days % 365) + "y " + \
    ((days / 365) % 12) + "m " +
    (days % (365 * 12)) + "d"

  MSG [ymd_diff($U, date($Uy, 12, 25))] until Christmas

Converting that precisely to "Y years, M months, D days" is a bit ugly
though, depending on how smartly you want it to present. If you don't
mind a mix of positive and negative values it's pretty
straightforward:

  FSET ymd_diff(d1, d2) \
    (year(d1) - year(d2)) + "y " + \
    (month(d1) - month(m2)) + m " + \
    (day(d1) - day(d2)) + "d"

but this can end up with weird cases like

  3y -3m 8d

which is really 2 years, 9 months, and 8 days.  To make all the
numbers positive this should do the trick:

  # ymd_diff_gt requires d2>=d1
  # ymd_diff takes care of swapping if needed
  FSET ymd_diff_gt(d1, d2) \
    iif(year(d2) > year(d1), \
      (year(d2) - year(d1)) - ( \
        (monnum(d2) < monnum(d1)) \
        || \
        (monnum(d2) == monnum(d1) && day(d2) < day(d1)) \
        ), \
      0 \
      ) + "y " + \
    iif(monnum(d2) > monnum(d1), \
      (monnum(d2) - monnum(d1)) - (day(d2) < day(d1)), \
      iif(monnum(d2) < monnum(d1), \
        (12 + monnum(d2) - monnum(d1)) - (day(d2) < day(d1)), \
        iif(day(d2) < day(d1), 11, 0) \
        )) + "m " + \
    iif(day(d2) >= day(d1), \
      day(d2) - day(d1), \
      (daysinmon(monnum(d1), year(d2)) + day(d2)) - day(d1) \
      ) + "d"

  FSET ymd_diff(d1, d2) \
    iif(d1 > d2, ymd_diff_gt(d2, d1) + " ago",\
    ymd_diff_gt(d1, d2)\
    )

then use the ymd_diff(d1, d2) function:

  MSG Christmas: [ymd_diff($U, date($Uy, 12, 25))]

As I said...that function is U G L Y.

I can't guarantee that function, but I threw a bunch of test-cases
and edge-cases against it until they all passed.  Hopefully it works
for you; let me know if you encounter any oddities.

> one I am interested in (Pension Day):
> 
> # 3rd last working day of the month 
> REM 1 -3 OMIT Sat Sun MSG Payday
> 
> so:
> REM {today} to 1 -3 OMIT Sat Sun MSG $dayc

I'm not sure I follow your question here (I'm unfamiliar with
"Pension Day").  I think you're doing some sort of retirement
count-down so could do something like

  SET retirement date(2021, 4, 1)

  REM 1 -3 OMIT Sat Sun MSG Retire [ymd_diff($U, retirement)]

> and birthdays 
> 
> Bob (will be) 47 in 3m 6d
> Christmas (in) 5m 16d
> Debian 11 (in) 3y 5m 18d
> 
> 01012000 (was) 7354d ago
> 01012000 (was) 20y 1m 18d

Again, I'm not sure I have all the information here to create a
corresponding reminder for these. 

Some cases might be a little tricky depending on the baseyr() built
into your application.  On my local version, this is 1990:

  $ echo 'MSG [baseyr()]' | remind -

but if you try to hard-code literal dates before that for some events,
you'll encounter issues.

-tim







More information about the Remind-fans mailing list