time utilities #35
Aliases: time utilities, time
27 verbs · 23 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
day | this none this | rxd | #35 | 15 |
month | this none this | rxd | #35 | 15 |
ampm | this none this | rxd | #35 | 22 |
to_seconds | this none this | rxd | #35 | 4 |
sun | this none this | rxd | #35 | 10 |
from_ctime | this none this | rxd | #35 | 13 |
dhms dayshoursminutesseconds | this none this | rxd | #35 | 21 |
english_time | this none this | rxd | #35 | 40 |
from_day | this none this | rxd | #35 | 18 |
from_month | this none this | rxd | #35 | 21 |
dst_midnight | this none this | rxd | #35 | 3 |
time_sub | this none this | rxd | #35 | 86 |
mmddyy ddmmyy | this none this | rxd | #35 | 21 |
parse_english_time_interval | this none this | rxd | #35 | 49 |
seconds_until_date | this none this | rxd | #35 | 20 |
seconds_until_time | this none this | rxd | #35 | 7 |
daytime_to_str | this none this | rxd | #35 | 18 |
english_time_rounded | this none this | rxd | #35 | 41 |
abbrev_ctime | this none this | rxd | #35 | 13 |
longdate longdate_american | this none this | rxd | #35 | 15 |
dhms_with_letters | this none this | rxd | #35 | 22 |
dhms_short | this none this | rxd | #35 | 10 |
daytime_to_secs | this none this | rxd | #35 | 12 |
jdn julian_day_number | this none this | rxd | #35 | 4 |
jdn_to_interval | this none this | rxd | #35 | 8 |
day_number | none none none | rxd | #35 | 15 |
parts | this none this | rxd | #35 | 12 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
monthlens | #35 | rc | #29 | list of 12{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} |
timezones | #35 | rc | #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 | #35 | rc | #29 | 2427 |
ctcd | #35 | rc | #29 | 7276 |
ct | #35 | rc | #29 | 7934 |
corr | #35 | rc | #29 | -122 |
dayabbrs | #35 | rc | #29 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"} |
days | #35 | rc | #29 | {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} |
months | #35 | rc | #29 | list of 12{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"} |
monthabbrs | #35 | rc | #29 | list of 12{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} |
zones | #35 | rc | #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 | #35 | rc | #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 | #72 | rc | #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 | #1 | rc | #29 | {"time utilities", "time"} |
description | #1 | rc | #29 | {"This is the time utilities utility package. See `help $time_utils' for more details."} |
object_size | #1 | r | #29 | {28605, 1298433815} |
hidden_verbs | #1 | rc | #29 | <clear> |
phelp_msg | #1 | rc | #29 | <clear> |
weight | #1 | rc | #29 | <clear> |
owner_verbs | #1 | rc | #29 | <clear> |
plural_name | #1 | rc | #29 | <clear> |
client_image | #1 | rc | #29 | <clear> |
listening | #1 | rc | #29 | <clear> |
Ancestry
Ancestors (nearest first): #72 Generic Utilities Package → #1 root
Children: none
Call graph
Source
day
Referenced by
- #35:time_sub line 55:
$time_utils:day
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
Referenced by
- #35:time_sub line 59:
$time_utils:month
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
Referenced by
- #130:history line 33:
$time_utils:ampm
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
Referenced by
- #35:seconds_until_time line 5:
$time_utils:to_seconds - #35:seconds_until_time line 6:
$time_utils:to_seconds
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
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
Referenced by
- #38:__convert_new line 23:
$time_utils:from_ctime
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
Referenced by
- #4:wel*come line 15:
$time_utils:dhms - #48:tell_eta line 8:
$tu:dhms - #69:display_cache line 10:
$time_utils:dhms - #75:measurement_task line 19:
$time_utils:dhms
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
Referenced by
- #4:up*time line 4:
$time_utils:english_time - #4:check_for_shutdown line 9:
$time_utils:english_time - #4:temp_newt_registration_string line 1:
$time_utils:english_time - #6:idle line 24:
$time_utils:english_time - #6:@age line 21:
$time_utils:english_time - #6:@age line 32:
$time_utils:english_time - #37:@set_expire line 13:
$time_utils:english_time - #37:@set_expire line 22:
$time_utils:english_time - #37:@register line 18:
$time_utils:english_time - #37:@register line 20:
$time_utils:english_time - #37:@register line 27:
$time_utils:english_time - #37:@validate line 18:
$time_utils:english_time - #49:@blacklist line 28:
$time_utils:english_time - #49:@blacklist line 111:
$time_utils:english_time - #49:@blacklist line 142:
$time_utils:english_time - #49:@deprog*rammer line 29:
$time_utils:english_time - #49:@shutdown line 32:
$time_utils:english_time - #59:show_expire line 5:
$time_utils:english_time - #65:clean_status line 11:
$time_utils:english_time - #103:meat_reaper line 1:
$tu:english_time - #103:meat_reaper line 20:
$tu:english_time - #167:summary line 36:
$time_utils:english_time - #296:_handle_error line 7:
$time_utils:english_time - #296:_do line 11:
$time_utils:english_time - #296:_run line 36:
$time_utils:english_time
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
Referenced by
- #38:_parse_date line 13:
$time_utils:from_day - #43:@flush line 18:
$time_utils:from_day
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
Referenced by
- #35:seconds_until_date line 11:
$time_utils:from_month - #38:_parse_date line 20:
$time_utils:from_month - #38:_parse_date line 26:
$time_utils:from_month - #43:@flush line 19:
$time_utils:from_month
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
Referenced by
- #38:_parse_date line 4:
$time_utils:dst_midnight - #38:_parse_date line 6:
$time_utils:dst_midnight - #38:_parse_date line 8:
$time_utils:dst_midnight - #38:_parse_date line 10:
$time_utils:dst_midnight - #38:_parse_date line 12:
$time_utils:dst_midnight - #38:_parse_date line 20:
$time_utils:dst_midnight - #38:_parse_date line 26:
$time_utils:dst_midnight
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
Referenced by
- #49:@blacklist line 142:
$time_utils:time_sub - #49:display_list line 15:
$time_utils:time_sub - #49:display_list line 22:
$time_utils:time_sub - #53:to_text line 7:
$time_utils:time_sub - #90:timestr line 2:
$time_utils:time_sub - #118:command_history line 23:
$time_utils:time_sub - #118:command_history line 27:
$time_utils:time_sub
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
Referenced by
- #90:timestr line 2:
$time_utils:ddmmyy
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
Referenced by
- #35:parse_english_time_interval line 12:
$time_utils:parse_english_time_interval - #37:@set_expire line 14:
$time_utils:parse_english_time_interval - #49:@temp-newt line 10:
$time_utils:parse_english_time_interval - #49:parse_templist_duration line 24:
$time_utils:parse_english_time_interval - #59:parse_expire line 12:
$time_utils:parse_english_time_interval
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
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
Referenced by
- #35:seconds_until_date line 12:
this:seconds_until_time - #35:seconds_until_date line 13:
this:seconds_until_time
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
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
Referenced by
- #49:@prog-check line 43:
$time_utils:english_time_rounded - #49:@prog-check line 52:
$time_utils:english_time_rounded
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
Referenced by
- #23:display_seq_headers line 15:
$time_utils:abbrev_ctime - #50:seccheck line 56:
$time_utils:abbrev_ctime - #150:service_long_queue line 15:
$tu:abbrev_ctime - #253:format_entry line 6:
$time_utils:abbrev_ctime - #293:txt_log line 16:
$time_utils:abbrev_ctime - #293:txt_log line 28:
$time_utils:abbrev_ctime - #293:txt_log line 37:
$time_utils:abbrev_ctime - #293:msg_summary_line line 9:
$time_utils:abbrev_ctime - #293:extra_text line 37:
$time_utils:abbrev_ctime - #293:msg_summary_line_colored line 11:
$time_utils:abbrev_ctime - #293:old_txt_log line 15:
$time_utils:abbrev_ctime - #293:old_txt_log line 22:
$time_utils:abbrev_ctime - #296:_readlog line 4:
$time_utils:abbrev_ctime
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
Referenced by
- #130:history line 33:
$time_utils:longdate - #297:report_from_issuelists line 42:
$tu:longdate
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
Referenced by
- #50:paramedic line 4:
$time_utils:dhms_with_letters
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
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
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
Referenced by
- #35:jdn_to_interval line 2:
this:julian_day_number - #293:most_interesting line 3:
$tu:julian_day_number
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
Referenced by
- #293:jdn_msg_seq line 2:
$tu:jdn_to_interval - #293:most_interesting line 4:
$tu:jdn_to_interval
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
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
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]};