View/Edit #8495:english_time

Switch to edit mode.

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

Verb arguments: this none this
Verb perms: Readable eXecutable NOT-Debug
Verb owned by: Ezran (#3936)

You are not logged in.

[home | help | who | search | setup | code]