/since /until Date & Time

By raccoon on Nov 11, 2019

Figure out how long ago since, or until, a certain calendar date and time.

  • Only 2075w 4d 20h 3m 33s (14529.84 days) since Thu 31 Jan 1980 00:00:00

Commands: /since or /until or /sincegmt or /untilgmt
Parameters: <date> or <time> or <date time> or <time date>
Examples: ...

/since Tuesday, January 31, 1980 00:00:00
/since Jan 31st 80 12:00 am
/since 01 Jan 01:23 1980 pm
/since 1980 01:23:45 01 pm Jan
/since 31/01/1980 (or) 1980/01/31 12:34:56
/since 31-01-1980 (or) 12:34:56 1980-01-31 pm
/since 5:00 pm (or) /until 5:00 pm
/sincegmt 5:00 pm (or) /untilgmt 5:00 pm

  • days-of-week are gracefully ignored. (ie, Tue or Tuesday)
  • known ordinal suffixes st nd rd th are gracefully ignored.
  • two digit years will be recognized only if they're between 32 and 99.
  • single or double digit month, day, hour, minute, seconds are fine.
  • dates separated by space must use the spelling of the month, not the number,
    and the order doesn't matter as long as a month, day and year are present.
  • dates separated by slash or hyphen must be in either d/m/y or y/m/d order.
  • time can appear on either side (or inside) the date, in 12h or 24h format.
  • am pm AM PM are accepted, without periods, anywhere to the right of time.
  • /since and /until are exactly the same alias, past and future are calculated by math.
  • /sincegmt and /untilgmt will treat the specified date/time as GMT aka UTC.
; /until 25/12/2019  /since 2 Nov 2016  /untilgmt 5:00 pm  /sincegmt 1/1/2020 0:0:0
until {
  var %gmt = 0
  if ($1 == gmt) { var %gmt = 1 | tokenize 32 $2- }
  if ($regex($1-,/^[0-9:apm. ]+$/i)) { tokenize 32 $date $1- }
  var %then = $ctime($1-)
  if (!%then) { echo -atic notice * Invalid date/time $chr(31) $+ $1- $+ $chr(31) | return }
  var %now = $iif(%gmt,$gmt,$ctime)
  var %delta = $calc(%now - %then)
  var %until = $iif(%delta > 0,since,until)
  var %durs = $remove($duration($abs(%delta)),ks,k,ays,ay,rs,r,ins,in,ecs,ec)
  var %days = $round($calc($abs(%delta) / 86400),2)
  echo -atic notice * Only $chr(31) $+ %durs $+ $chr(31) ( $+ %days days) $&
    %until $chr(31) $+ $asctime(%then,ddd dd mmm yyyy HH:nn:ss) $+ $chr(32)
} ; by Raccoon 2019
since { until $1- }
sincegmt { until gmt $1- }
untilgmt { until gmt $1- }

I dare not attempt to clean up below this line, for the site will inexplicably crash.

Code
more code
code goes here
/echo -a test

Enjoy!

test

test

test

testy

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.