time utilities #35

Parent #72Owner #29Flags readSource hellcore/hellcore.db

Aliases: time utilities, time

27 verbs · 23 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
daythis none thisrxd#3515
monththis none thisrxd#3515
ampmthis none thisrxd#3522
to_secondsthis none thisrxd#354
sunthis none thisrxd#3510
from_ctimethis none thisrxd#3513
dhms dayshoursminutessecondsthis none thisrxd#3521
english_timethis none thisrxd#3540
from_daythis none thisrxd#3518
from_monththis none thisrxd#3521
dst_midnightthis none thisrxd#353
time_subthis none thisrxd#3586
mmddyy ddmmyythis none thisrxd#3521
parse_english_time_intervalthis none thisrxd#3549
seconds_until_datethis none thisrxd#3520
seconds_until_timethis none thisrxd#357
daytime_to_strthis none thisrxd#3518
english_time_roundedthis none thisrxd#3541
abbrev_ctimethis none thisrxd#3513
longdate longdate_americanthis none thisrxd#3515
dhms_with_lettersthis none thisrxd#3522
dhms_shortthis none thisrxd#3510
daytime_to_secsthis none thisrxd#3512
jdn julian_day_numberthis none thisrxd#354
jdn_to_intervalthis none thisrxd#358
day_numbernone none nonerxd#3515
partsthis none thisrxd#3512

Properties

PropertyDefinerFlagsOwnerValue
monthlens#35rc#29
list of 12{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
timezones#35rc#29
list of 15{{"AuEST", -10}, {"AuCST", -9}, {"AuWST", -8}, {"WET", -1}, {"GMT", 0}, {"AST", 4}, {"EDT", 4}, {"EST", 5}, {"CDT", 5}, {"CST", 6}, {"MDT", 6}, {"MST", 7}, {"PDT", 7}, {"PST", 8}, {"HST", 10}}
stsd#35rc#292427
ctcd#35rc#297276
ct#35rc#297934
corr#35rc#29-122
dayabbrs#35rc#29{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
days#35rc#29{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
months#35rc#29
list of 12{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
monthabbrs#35rc#29
list of 12{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
zones#35rc#29
list of 5{{{"est", "edt", "Massachusetts", "MA"}, 10800}, {{"cst", "cdt"}, 7200}, {{"mst", "mdt"}, 3600}, {{"pst", "pdt", "California", "CA", "Lambda"}, 0}, {{"gmt"}, 28800}}
time_units#35rc#29
list of 7{{31536000, "year", "years", "yr", "yrs"}, {2628000, "month", "months", "mo", "mos"}, {604800, "week", "weeks", "wk", "wks"}, {86400, "day", "days", "dy", "dys"}, {3600, "hour", "hours", "hr", "hrs"}, {60, "minute", "minutes", "min", "mins"}, {1, "second", "seconds", "sec", "secs"}}
help_msg#72rc#29
list of 32{" Converting from seconds-since-1970 ", "dhms (time) => string ...DD:HH:MM:SS", "english_time (time[, reference time)=> string of y, m, d, h, m, s", "", " Converting to seconds", "to_seconds (\"hh:mm:ss\") => seconds since 00:00:00", "from_ctime (ctime) => corresponding time-since-1970", "from_day (day_of_week, which) => time-since-1970 for the given day*", "from_month (month, which) => time-since-1970 for the given month*", " (* the first midnight of that day/month)", "parse_english_time_interval(\"n1 u1 n2 u2...\")", " => seconds in interval", "seconds_until_time(\"hh:mm:ss\") => number of seconds from now until then", "seconds_until_date(\"month\",day,\"hh:mm:ss\",flag ", " => number of seconds from now until then", " (see verb help for details)", "", " Converting to some standard English formats", "day ([[c]time]) => what day it is", "month ([[c]time]) => what month it is", "ampm ([[c]time][, precision]) => what time it is, with am or pm", "mmddyy ([[c]time]) => date in format MM/DD/YY", "ddmmyy ([[c]time]) => date in format DD/MM/YY", "longdate ([[c]time]) => Dayname MM Monthname YYYY", "longdate_american([[c]time]) => Dayname, Monthname MM, YYYY", "", " Substitution", "time_sub (string, time) => substitute time information", "", " Miscellaneous", "sun ([time]) => angle between sun and zenith", "dst_midnight (time) "}
aliases#1rc#29{"time utilities", "time"}
description#1rc#29{"This is the time utilities utility package. See `help $time_utils' for more details."}
object_size#1r#29{28605, 1298433815}
hidden_verbs#1rc#29<clear>
phelp_msg#1rc#29<clear>
weight#1rc#29<clear>
owner_verbs#1rc#29<clear>
plural_name#1rc#29<clear>
client_image#1rc#29<clear>
listening#1rc#29<clear>

Ancestry

Ancestors (nearest first): #72 Generic Utilities Package#1 root

Children: none

Call graph

calls n35_0 #35:day n20_38 #20:explode n35_0->n20_38 n35_1 #35:month n35_1->n20_38 n35_2 #35:ampm n35_2->n20_38 n35_4 #35:sun n18_30 #18:cos n35_4->n18_30 n18_29 #18:sin n35_4->n18_29 n35_5 #35:from_ctime n35_5->n20_38 n47_17 #47:assoc n35_5->n47_17 n35_7 #35:english_time n48_8 #48:suspend_if_needed n35_7->n48_8 n20_6 #20:english_list n35_7->n20_6 n35_8 #35:from_day n20_22 #20:find_prefix n35_8->n20_22 n35_9 #35:from_month n35_9->n20_22 n35_11 #35:time_sub n35_11->n35_0 n35_11->n20_38 n35_11->n35_1 n107_43 #107:tell n35_11->n107_43 n20_9 #20:trim n35_11->n20_9 n20_2 #20:right n35_11->n20_2 n35_12 #35:mmddyy n35_12->n20_38 n35_13 #35:parse_english_time_interval n35_13->n35_13 n20_39 #20:words n35_13->n20_39 n47_9 #47:setremove_all n35_13->n47_9 n20_24 #20:is_integer n35_13->n20_24 n35_14 #35:seconds_until_date n35_14->n35_9 n35_15 #35:seconds_until_time n35_14->n35_15 n35_3 #35:to_seconds n35_15->n35_3 n35_16 #35:daytime_to_str n18_13 #18:mod n35_16->n18_13 n35_17 #35:english_time_rounded n35_17->n48_8 n35_18 #35:abbrev_ctime n35_18->n20_38 n35_19 #35:longdate n35_19->n20_38 n20_5 #20:from_list n35_19->n20_5 n35_22 #35:daytime_to_secs n35_22->n20_38 n35_24 #35:jdn_to_interval n35_23 #35:jdn n35_24->n35_23 n35_25 #35:day_number n35_25->n20_38 n35_26 #35:parts n35_26->n20_38

Source

day

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Given a time() or ctime()-style date, this returns the full name of the day.";
2"With no args, uses now.";
3if (args)
4if (typeof(args[1]) == INT)
5time = ctime(args[1]);
6elseif (typeof(args[1]) == STR)
7time = args[1];
8else
9return E_TYPE;
10endif
11else
12time = ctime();
13endif
14dayabbr = $string_utils:explode(time)[1];
15return this.days[dayabbr in this.dayabbrs];

month

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Given a time() or ctime()-style date, this returns the full name";
2"of the month. With no args, uses now.";
3if (args)
4if (typeof(args[1]) == INT)
5time = ctime(args[1]);
6elseif (typeof(args[1]) == STR)
7time = args[1];
8else
9return E_TYPE;
10endif
11else
12time = ctime();
13endif
14monthabbr = $string_utils:explode(time)[2];
15return this.months[monthabbr in this.monthabbrs];

ampm

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Return a time in the form [h]h[:mm[:ss]] {a.m.|p.m.}.  Args are";
2"[1]   (optional) either a time() or ctime() style date";
3"[2]   (optional) the precision desired--1 for hours, 2 for minutes,";
4"        3 for seconds.  If not given, precision defaults to minutes";
5{?time = ctime(), ?precision = 2} = args;
6if (typeof(time) == INT)
7time = ctime(time);
8elseif (typeof(time) != STR)
9return E_TYPE;
10endif
11time = $string_utils:explode(time)[4];
12hour = toint(time[1..2]);
13if (hour == 0)
14time = ("12" + time[3..(precision * 3) - 1]) + " a.m.";
15elseif (hour == 12)
16time = time[1..(precision * 3) - 1] + " p.m.";
17elseif (hour > 12)
18time = (tostr(hour - 12) + time[3..(precision * 3) - 1]) + " p.m.";
19else
20time = (tostr(hour) + time[3..(precision * 3) - 1]) + " a.m.";
21endif
22return time;

to_seconds

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Given string hh:mm:ss ($string_utils:explode(ctime(time))[4]), this returns";
2"the number of seconds elapsed since 00:00:00.  I can't remember why I";
3"created this verb, but I'm sure it serves some useful purpose.";
4return (((60 * 60) * toint(args[1][1..2])) + (60 * toint(args[1][4..5]))) + toint(args[1][7..8]);

sun

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

none

Source

1{?time = time()} = args;
2r = 10000;
3h = (r * r) + (r / 2);
4t = ((time + 120) % 86400) / 240;
5s = (5 * ((time - 14957676) % 31556952)) / 438291;
6phi = (s + t) + this.corr;
7cs = $trig_utils:cos(s);
8spss = ((($trig_utils:sin(phi) * $trig_utils:sin(s)) + h) / r) - r;
9cpcs = ((($trig_utils:cos(phi) * cs) + h) / r) - r;
10return (((((this.stsd * cs) - (this.ctcd * cpcs)) - (this.ct * spss)) + h) / r) - r;

from_ctime

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Given a string such as returned by ctime(), return the corresponding time-in-seconds-since-1970 time returned by time(), or E_DIV if the format is wrong in some essential way.";
2words = $string_utils:explode(args[1]);
3if (length(words) == 5)
4"Arrgh!  the old ctime() didn't return a time zone, yet it arbitrarily decides whether it's standard or daylight savings time.  URK!!!!!";
5words = listappend(words, "PST");
6endif
7if ((((length(words) != 6) || (length(hms = $string_utils:explode(words[4], ":")) != 3)) || (!(month = words[2] in this.monthabbrs))) || (!(zone = $list_utils:assoc(words[6], this.timezones))))
8return E_DIV;
9endif
10year = toint(words[5]);
11day = ({-1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}[month] + toint(words[3])) + (year * 366);
12zone = zone[2];
13return (((((((((((((day - ((day + 1038) / 1464)) - ((day + 672) / 1464)) - ((day + 306) / 1464)) - ((day + 109740) / 146400)) - ((day + 73140) / 146400)) - ((day + 36540) / 146400)) - 719528) * 24) + toint(hms[1])) + zone) * 60) + toint(hms[2])) * 60) + toint(hms[3]);

dhms dayshoursminutesseconds

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1s = args[1];
2if (s < 0)
3return "-" + this:(verb)(-s);
4endif
5m = s / 60;
6s = s % 60;
7if (m)
8ss = tostr((s < 10) ? ":0" | ":", s);
9h = m / 60;
10m = m % 60;
11if (h)
12ss = tostr((m < 10) ? ":0" | ":", m, ss);
13d = h / 24;
14h = h % 24;
15return tostr(@d ? {d, (h < 10) ? ":0" | ":"} | {}, h, ss);
16else
17return tostr(m, ss);
18endif
19else
20return tostr(s);
21endif

english_time

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"english_time(time [,reference time]): returns the time as a string of";
2"years, months, days, hours, minutes and seconds using the reference time as";
3"the start time and incrementing forwards. it can be given in either ctime()";
4"or time() format. if a reference time is not given, it is set to time().";
5{_time, ?reftime = time()} = args;
6if (_time < 1)
7return "0 seconds";
8endif
9_ctime = (typeof(reftime) == INT) ? ctime(reftime) | reftime;
10seclist = {60, 60, 24};
11units = {"year", "month", "day", "hour", "minute", "second"};
12timelist = {};
13for unit in (seclist)
14timelist = {_time % unit, @timelist};
15_time = _time / unit;
16endfor
17months = 0;
18month = _ctime[5..7] in $time_utils.monthabbrs;
19year = toint(_ctime[21..24]);
20"attribution: the algorithm used is from the eminently eminent g7.";
21while (_time >= (days = this.monthlens[month] + (((month == 2) && ((year % 4) == 0)) && (!((year % 400) in {100, 200, 300})))))
22_time = _time - days;
23months = months + 1;
24if ((month = month + 1) > 12)
25year = year + 1;
26month = 1;
27endif
28$command_utils:suspend_if_needed(0);
29endwhile
30timelist = {months / 12, months % 12, _time, @timelist};
31for unit in (units)
32i = unit in units;
33if (timelist[i] > 0)
34units[i] = ((tostr(timelist[i]) + " ") + units[i]) + ((timelist[i] == 1) ? "" | "s");
35else
36units = listdelete(units, i);
37timelist = listdelete(timelist, i);
38endif
39endfor
40return $string_utils:english_list(units);

from_day

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"from_day(day_of_week,which)";
2"numeric time (seconds since 1970) corresponding to midnight (PST) of the given weekday.  Use either the name of the day or a 1..7 number (1==Sunday,...)";
3"  which==-1 => use most recent such day.";
4"  which==+1 => use first upcoming such day.";
5"  which==0  => use closest such day.";
6"larger (absolute) values for which specify a certain number of weeks into the future or past.";
7{day, ?dir = 0} = args;
8if (!(toint(day) || (day = $string_utils:find_prefix(day, this.days))))
9return E_DIV;
10endif
11delta = {288000, 374400, 460800, 547200, 28800, 115200, 201600}[toint(day)];
12time = time() - delta;
13if (dir)
14time = (time / 604800) + ((dir > 0) ? dir | (dir + 1));
15else
16time = (time + 302400) / 604800;
17endif
18return (time * 604800) + delta;

from_month

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"from_month(month,which[,d])";
2"numeric time (seconds since 1970) corresponding to midnight (PST) of the dth (first) day of the given month.  Use either the month name or a 1..12 number (1==January,...)";
3"  which==-1 => use most recent such month.";
4"  which==+1 => use first upcoming such month.";
5"  which==0  => use closest such month.";
6"larger (absolute) values for which specify a certain number of years into the future or past.";
7{month, ?dir = 0, ?dth = 1} = args;
8if (!(toint(month) || (month = $string_utils:find_prefix(month, this.months))))
9return E_DIV;
10endif
11delta = ({0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}[month] + dth) - 1;
12day = (time() - 28800) / 86400;
13day = (day - ((day + 672) / 1461)) - delta;
14if (dir)
15day = ((day / 365) + dir) + (dir <= 0);
16else
17day = ((2 * day) + 365) / 730;
18endif
19day = (day * 365) + delta;
20day = day + ((day + 671) / 1460);
21return (day * 86400) + 28800;

dst_midnight

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Takes a time that is midnight PST and converts it to the nearest PDT midnight time if it's during that part of the year where we use PDT.";
2time = args[1];
3return time - (3600 * (((toint(ctime(time)[12..13]) + 12) % 24) - 12));

time_sub

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Works like pronoun substitution, but substitutes time stuff.";
2"Call with time_sub(string, time). returns a string.";
3"time is an optional integer in time() format.  If omitted, time() is used.";
4"Macros which are unknown are ignored. $Q -> the empty string.";
5"Terminal $ are ignored.";
6"$H -> hour #. $M -> min #. $S -> second #. 24-hour format, fixed width.";
7"$h, $m, $s same x/c have not-fixed format. 00:03:24 vs. 0:3:24";
8"$O/$o -> numeric hour in 12-hour format.";
9"$D -> long day name. $d -> short day name.";
10"$N -> long month name. $n -> short month name.";
11"$Y -> long year # (e.g. '1991'). $y -> short year # (e.g. '91')";
12"$Z -> the time zone    (added in by r'm later)";
13"$P/$p -> AM/PM, or am/pm.";
14"$T -> date number. $t -> date number with no extra whitespace etc.";
15"$1 -> Month in fixed-width numeric format (01-12)   (added by dpk)";
16"$2 -> Month in nonfixed numeric format (1-12)";
17"$3 -> Date in fixed-width format, 0-fill";
18"$$ -> $.";
19"";
20"This verb stolen from Ozymandias's #4835:time_subst.";
21res = "";
22{thestr, ?thetime = time()} = args;
23if ((typeof(thestr) != STR) || (typeof(thetime) != INT))
24player:tell("Bad arguments to time_subst.");
25return;
26endif
27itslength = length(thestr);
28if (!itslength)
29return "";
30endif
31done = 0;
32cctime = ctime(thetime);
33while (dollar = index(thestr, "$"))
34res = res + thestr[1..dollar - 1];
35if (dollar == length(thestr))
36return res;
37endif
38thechar = thestr[dollar + 1];
39thestr[1..dollar + 1] = "";
40if (thechar == "$")
41res = res + "$";
42elseif (!strcmp(thechar, "h"))
43res = res + $string_utils:trim(tostr(toint(cctime[12..13])));
44elseif (thechar == "H")
45res = res + cctime[12..13];
46elseif (!strcmp(thechar, "m"))
47res = res + $string_utils:trim(tostr(toint(cctime[15..16])));
48elseif (thechar == "M")
49res = res + cctime[15..16];
50elseif (!strcmp(thechar, "s"))
51res = res + $string_utils:trim(tostr(toint(cctime[18..19])));
52elseif (thechar == "S")
53res = res + cctime[18..19];
54elseif (!strcmp(thechar, "D"))
55res = res + $time_utils:day(thetime);
56elseif (thechar == "d")
57res = res + cctime[1..3];
58elseif (!strcmp(thechar, "N"))
59res = res + $time_utils:month(thetime);
60elseif (thechar == "n")
61res = res + cctime[5..7];
62elseif (!strcmp(thechar, "T"))
63res = res + cctime[9..10];
64elseif (thechar == "t")
65res = res + $string_utils:trim(cctime[9..10]);
66elseif (thechar == "O")
67res = res + tostr(((toint(cctime[12..13]) + 11) % 12) + 1);
68elseif (!strcmp(thechar, "p"))
69res = res + ((toint(cctime[12..13]) >= 12) ? "pm" | "am");
70elseif (thechar == "P")
71res = res + ((toint(cctime[12..13]) >= 12) ? "PM" | "AM");
72elseif (!strcmp(thechar, "y"))
73res = res + cctime[23..24];
74elseif (thechar == "Y")
75res = res + cctime[21..24];
76elseif (thechar == "Z")
77res = res + cctime[26..28];
78elseif (thechar == "1")
79res = res + $string_utils:right(tostr($string_utils:explode(cctime)[2] in this.monthabbrs), 2, "0");
80elseif (thechar == "2")
81res = res + tostr($string_utils:explode(cctime)[2] in this.monthabbrs);
82elseif (thechar == "3")
83res = res + $string_utils:subst(cctime[9..10], {{" ", "0"}});
84endif
85endwhile
86return res + thestr;

mmddyy ddmmyy

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Copied from Archer (#52775):mmddyy Tue Apr  6 17:04:26 1993 PDT";
2"Given a time() or ctime()-style date and an optional separator, this returns the MM/DD/YY or DD/MM/YY form of the date (depending on the verb called.)  The default seperator is '/'";
3"Uses now, if no args.";
4{?time = ctime(), ?divstr = "/"} = args;
5if (typeof(time) == INT)
6time = ctime(time);
7elseif (typeof(time) != STR)
8return E_TYPE;
9endif
10date = $string_utils:explode(time);
11day = toint(date[3]);
12month = date[2] in $time_utils.monthabbrs;
13year = date[5];
14daystr = (day < 10) ? "0" + tostr(day) | tostr(day);
15monthstr = (month < 10) ? "0" + tostr(month) | tostr(month);
16yearstr = tostr(year)[3..4];
17if (verb == "mmddyy")
18return tostr(monthstr, divstr, daystr, divstr, yearstr);
19else
20return tostr(daystr, divstr, monthstr, divstr, yearstr);
21endif

parse_english_time_interval

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"$time_utils:parse_english_time_interval(n1,u1,n2,u2,...)";
2"or $time_utils:parse_english_time_interval(\"n1 u1[,] [and] n2[,] u2 [and] ...\")";
3"There must be an even number of arguments, all of which must be strings,";
4" or there must be just one argument which is the entire string to be parsed.";
5"The n's are are numeric strings, and the u's are unit names.";
6"The known units are in $time_utils.time_units,";
7" which must be kept sorted with bigger times at the head.";
8"Returns the time represented by those words.";
9"For example,";
10" $time_utils:parse_english_time_interval(\"30\",\"secs\",\"2\",\"minutes\",\"31\",\"seconds\") => 181";
11if ((length(args) == 1) && index(args[1], " "))
12return $time_utils:parse_english_time_interval(@$string_utils:words(args[1]));
13endif
14a = $list_utils:setremove_all(args, "and");
15nargs = length(a);
16if (nargs % 2)
17return E_ARGS;
18endif
19nsec = 0;
20n = 0;
21for i in [1..nargs]
22if ((i % 2) == 1)
23if ($string_utils:is_numeric(a[i]))
24n = toint(a[i]);
25elseif (a[i] in {"a", "an"})
26n = 1;
27elseif (a[i] in {"no"})
28n = 0;
29else
30return E_INVARG;
31endif
32else
33unit = a[i];
34if (unit[$] == ",")
35unit = unit[1..$ - 1];
36endif
37ok = 0;
38for entry in ($time_utils.time_units)
39if ((!ok) && (unit in entry[2..$]))
40nsec = nsec + (entry[1] * n);
41ok = 1;
42endif
43endfor
44if (!ok)
45return E_INVARG;
46endif
47endif
48endfor
49return nsec;

seconds_until_date

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

none

Source

1"Copied from Ballroom Complex (#29992):from_date by Keelah! (#30246) Tue Jul 13 19:42:32 1993 PDT";
2":seconds_until_date(month,day,time,which)";
3"month is a string or the numeric representation of the month, day is a number, time is a string in the following format, hh:mm:ss.";
4"which==-1 => use most recent such month.";
5"which==+1 => use first upcoming such month.";
6"which==0 => use closest such month.";
7"This will return the number of seconds until the month, day and time given to it.";
8"Written by Keelah, on July 5, 1993.";
9{month, day, time, which} = args;
10converted = 0;
11converted = converted + $time_utils:from_month(month, which, day);
12current = this:seconds_until_time("12:00:00");
13get_seconds = this:seconds_until_time(time);
14if (get_seconds < 0)
15get_seconds = (get_seconds + 39600) - current;
16else
17get_seconds = (get_seconds + 39600) - current;
18endif
19converted = (converted + get_seconds) - time();
20return converted;

seconds_until_time

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Copied from Ballroom Complex (#29992):seconds_until by Keelah! (#30246) Tue Jul 13 19:42:37 1993 PDT";
2":seconds_until_time(hh:mm:ss)";
3"Given the string hh:mm:ss, this returns the number of seconds until that hh:mm:ss. If the hh:mm:ss is before the current time(), the number returned is a negative, else the number is a positive.";
4"Written by Keelah, on July 4, 1993.";
5current = $time_utils:to_seconds(ctime()[12..19]);
6time = $time_utils:to_seconds(args[1]);
7return toint(time) - toint(current);

daytime_to_str

Spec this none thisFlags rxdOwner #361Definer #35

Referenced by

none

Source

1daytime = args[1];
2hour = daytime / 3600;
3min = (daytime - (hour * 3600)) / 60;
4hour = $math_utils:mod(hour, 24);
5if (hour > 12)
6hour = hour - 12;
7ampm = "pm";
8elseif (hour == 12)
9ampm = "pm";
10elseif (hour == 0)
11hour = 12;
12ampm = "am";
13else
14ampm = "am";
15endif
16ctime = (((hour < 10) ? "0" | "") + tostr(hour)) + ":";
17ctime = (ctime + (((min < 10) ? "0" | "") + tostr(min))) + ampm;
18return ctime;

english_time_rounded

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Copied from time utilities (#43):english_time by Hacker (#36) Thu Sep  6 13:56:13 2007 CDT";
2"english_time(time [,reference time]): returns the time as a string of";
3"years, months, days, hours, minutes and seconds using the reference time as";
4"the start time and incrementing forwards. it can be given in either ctime()";
5"or time() format. if a reference time is not given, it is set to time().";
6{_time, ?reftime = time()} = args;
7if (_time < 1)
8return "0 seconds";
9endif
10_ctime = (typeof(reftime) == INT) ? ctime(reftime) | reftime;
11seclist = {60, 60, 24};
12units = {"year", "month", "day", "hour", "minute", "second"};
13timelist = {};
14for unit in (seclist)
15timelist = {_time % unit, @timelist};
16_time = _time / unit;
17endfor
18months = 0;
19month = _ctime[5..7] in $time_utils.monthabbrs;
20year = toint(_ctime[21..24]);
21"attribution: the algorithm used is from the eminently eminent g7.";
22while (_time >= (days = this.monthlens[month] + (((month == 2) && ((year % 4) == 0)) && (!((year % 400) in {100, 200, 300})))))
23_time = _time - days;
24months = months + 1;
25if ((month = month + 1) > 12)
26year = year + 1;
27month = 1;
28endif
29$command_utils:suspend_if_needed(0);
30endwhile
31timelist = {months / 12, months % 12, _time, @timelist};
32for unit in (units)
33i = unit in units;
34if (timelist[i] > 0)
35units[i] = ((tostr(timelist[i]) + " ") + units[i]) + ((timelist[i] == 1) ? "" | "s");
36else
37units = listdelete(units, i);
38timelist = listdelete(timelist, i);
39endif
40endfor
41return units[1];

abbrev_ctime

Spec this none thisFlags rxdOwner #361Definer #35

Referenced by

Source

1":abbrev_time([INT time]) => STR short time depending on how long ago it was.";
2"if it wasn't this month, it's mon dy year, otherwise, mon dy time.";
3{?time = time()} = args;
4{dow, mon, day, tm, yr, tz} = $su:explode(ctime(time));
5{nowdow, nowmon, nowday, nowtime, nowyr, nowtz} = $su:explode(ctime());
6if ((yr != nowyr) || (mon != nowmon))
7return tostr(mon, " ", day, " ", yr);
8else
9if ((nowday == day) && (nowmon == mon))
10return tostr("Today ", tm[1..5]);
11endif
12return tostr(mon, " ", day, " ", tm[1..5]);
13endif

longdate longdate_american

Spec this none thisFlags rxdOwner #361Definer #35

Referenced by

Source

1{?time = ctime()} = args;
2if (typeof(time) == INT)
3time = ctime(time);
4elseif (typeof(time) != STR)
5raise(E_TYPE);
6endif
7{dname, mname, mday, time, year} = $su:explode(time)[1..5];
8dname = $tu.days[dname in $tu.dayabbrs];
9mname = $tu.months[mname in $tu.monthabbrs];
10if (verb == "longdate")
11return $su:from_list({dname, mday, mname, year}, " ");
12else
13m = tostr(mname, " ", mday);
14return $su:from_list({dname, m, year}, ", ");
15endif

dhms_with_letters

Spec this none thisFlags rxdOwner #29Definer #35

Referenced by

Source

1"Copied from time utilities (#43):dhms by Hacker (#36) Fri Apr 30 21:48:30 2010 CDT";
2s = args[1];
3if (s < 0)
4return "-" + this:(verb)(-s);
5endif
6m = s / 60;
7s = s % 60;
8if (m)
9ss = tostr("m", s, "s");
10h = m / 60;
11m = m % 60;
12if (h)
13ss = tostr("h", m, ss);
14d = h / 24;
15h = h % 24;
16return tostr(@d ? {d, "d"} | {}, h, ss);
17else
18return tostr(m, ss);
19endif
20else
21return tostr(s, "s");
22endif

dhms_short

Spec this none thisFlags rxdOwner #361Definer #35

Referenced by

none

Source

1{secs} = args;
2if (d = secs / 86400)
3return tostr(d, "d");
4elseif (h = secs / 3600)
5return tostr(h, "h");
6elseif (m = secs / 60)
7return tostr(m, "m");
8else
9return tostr(secs, "s");
10endif

daytime_to_secs

Spec this none thisFlags rxdOwner #361Definer #35

Referenced by

none

Source

1":daytime_to_secs(STR) => INT -- converts things like 03:48:39 to a number of seconds since midnight.";
2{timestr} = args;
3broken = $su:explode(timestr, ":");
4if (length(broken) == 3)
5{h, m, s} = broken;
6return ((tonum(h) * 3600) + (tonum(m) * 60)) + tonum(s);
7elseif (length(broken) == 2)
8{m, s} = broken;
9return (tonum(m) * 60) + tonum(s);
10else
11raise(E_INVARG);
12endif

jdn julian_day_number

Spec this none thisFlags rxdOwner #361Definer #35

Referenced by

Source

1":julian_day_number([INT time]) -> INT days since January 1 4713 BC";
2{?when = time()} = args;
3when = when - 18000;
4return (when / 86400) + 2440587;

jdn_to_interval

Spec this none thisFlags rxdOwner #361Definer #35

Referenced by

Source

1":jdn_to_interval([INT julian day number]) -> convert the given JDN, or today, into a list of {INT unixtime at 12:00:00 am, INT unixtime at 11:59:59 pm}";
2{?jdn = this:julian_day_number()} = args;
3jdn = jdn - 2440587;
4daystart = (jdn * 86400) - 43200;
5"adjust to CDT";
6daystart = daystart - 25200;
7dayend = daystart + 86399;
8return {daystart, dayend};

day_number

Spec none none noneFlags rxdOwner #29Definer #35

Referenced by

none

Source

1"Given a time() or ctime()-style date, this returns the number of the day.";
2"With no args, uses now.";
3if (args)
4if (typeof(args[1]) == INT)
5time = ctime(args[1]);
6elseif (typeof(args[1]) == STR)
7time = args[1];
8else
9return E_TYPE;
10endif
11else
12time = ctime();
13endif
14dayabbr = $string_utils:explode(time)[1];
15return dayabbr in this.dayabbrs;

parts

Spec this none thisFlags rxdOwner #361Definer #35

Referenced by

none

Source

1{?time = ctime(), ?include_date = 0} = args;
2if (typeof(time) == INT)
3time = ctime(time);
4elseif (typeof(time) != STR)
5raise(E_INVARG);
6endif
7pieces = $string_utils:explode(time);
8hms = {toint(pieces[4][1..2]), toint(pieces[4][4..5]), toint(pieces[4][7..8])};
9if (!include_date)
10return hms;
11endif
12return {@hms, pieces[1] in this.dayabbrs, pieces[2] in this.monthabbrs, toint(pieces[3]), toint(pieces[5]), pieces[6]};