| 1 | 
 # gettimeofday.awk --- get the time of day in a usable format | 
 
 
 
 
 
 | 2 | 
 # | 
 
 
 
 
 
 | 3 | 
 # Arnold Robbins, arnold@skeeve.com, Public Domain, May 1993 | 
 
 
 
 
 
 | 4 | 
 # | 
 
 
 
 
 
 | 5 | 
  | 
 
 
 
 
 
 | 6 | 
 # Returns a string in the format of output of date(1) | 
 
 
 
 
 
 | 7 | 
 # Populates the array argument time with individual values: | 
 
 
 
 
 
 | 8 | 
 #    time["second"]       -- seconds (0 - 59) | 
 
 
 
 
 
 | 9 | 
 #    time["minute"]       -- minutes (0 - 59) | 
 
 
 
 
 
 | 10 | 
 #    time["hour"]         -- hours (0 - 23) | 
 
 
 
 
 
 | 11 | 
 #    time["althour"]      -- hours (0 - 12) | 
 
 
 
 
 
 | 12 | 
 #    time["monthday"]     -- day of month (1 - 31) | 
 
 
 
 
 
 | 13 | 
 #    time["month"]        -- month of year (1 - 12) | 
 
 
 
 
 
 | 14 | 
 #    time["monthname"]    -- name of the month | 
 
 
 
 
 
 | 15 | 
 #    time["shortmonth"]   -- short name of the month | 
 
 
 
 
 
 | 16 | 
 #    time["year"]         -- year modulo 100 (0 - 99) | 
 
 
 
 
 
 | 17 | 
 #    time["fullyear"]     -- full year | 
 
 
 
 
 
 | 18 | 
 #    time["weekday"]      -- day of week (Sunday = 0) | 
 
 
 
 
 
 | 19 | 
 #    time["altweekday"]   -- day of week (Monday = 0) | 
 
 
 
 
 
 | 20 | 
 #    time["dayname"]      -- name of weekday | 
 
 
 
 
 
 | 21 | 
 #    time["shortdayname"] -- short name of weekday | 
 
 
 
 
 
 | 22 | 
 #    time["yearday"]      -- day of year (0 - 365) | 
 
 
 
 
 
 | 23 | 
 #    time["timezone"]     -- abbreviation of timezone name | 
 
 
 
 
 
 | 24 | 
 #    time["ampm"]         -- AM or PM designation | 
 
 
 
 
 
 | 25 | 
 #    time["weeknum"]      -- week number, Sunday first day | 
 
 
 
 
 
 | 26 | 
 #    time["altweeknum"]   -- week number, Monday first day | 
 
 
 
 
 
 | 27 | 
  | 
 
 
 
 
 
 | 28 | 
 function gettimeofday(time,    ret, now, i) | 
 
 
 
 
 
 | 29 | 
 { | 
 
 
 
 
 
 | 30 | 
     # get time once, avoids unnecessary system calls | 
 
 
 
 
 
 | 31 | 
     now = systime() | 
 
 
 
 
 
 | 32 | 
  | 
 
 
 
 
 
 | 33 | 
     # return date(1)-style output | 
 
 
 
 
 
 | 34 | 
     ret = strftime("%a %b %d %H:%M:%S %Z %Y", now) | 
 
 
 
 
 
 | 35 | 
  | 
 
 
 
 
 
 | 36 | 
     # clear out target array | 
 
 
 
 
 
 | 37 | 
     delete time | 
 
 
 
 
 
 | 38 | 
  | 
 
 
 
 
 
 | 39 | 
     # fill in values, force numeric values to be | 
 
 
 
 
 
 | 40 | 
     # numeric by adding 0 | 
 
 
 
 
 
 | 41 | 
     time["second"]       = strftime("%S", now) + 0 | 
 
 
 
 
 
 | 42 | 
     time["minute"]       = strftime("%M", now) + 0 | 
 
 
 
 
 
 | 43 | 
     time["hour"]         = strftime("%H", now) + 0 | 
 
 
 
 
 
 | 44 | 
     time["althour"]      = strftime("%I", now) + 0 | 
 
 
 
 
 
 | 45 | 
     time["monthday"]     = strftime("%d", now) + 0 | 
 
 
 
 
 
 | 46 | 
     time["month"]        = strftime("%m", now) + 0 | 
 
 
 
 
 
 | 47 | 
     time["monthname"]    = strftime("%B", now) | 
 
 
 
 
 
 | 48 | 
     time["shortmonth"]   = strftime("%b", now) | 
 
 
 
 
 
 | 49 | 
     time["year"]         = strftime("%y", now) + 0 | 
 
 
 
 
 
 | 50 | 
     time["fullyear"]     = strftime("%Y", now) + 0 | 
 
 
 
 
 
 | 51 | 
     time["weekday"]      = strftime("%w", now) + 0 | 
 
 
 
 
 
 | 52 | 
     time["altweekday"]   = strftime("%u", now) + 0 | 
 
 
 
 
 
 | 53 | 
     time["dayname"]      = strftime("%A", now) | 
 
 
 
 
 
 | 54 | 
     time["shortdayname"] = strftime("%a", now) | 
 
 
 
 
 
 | 55 | 
     time["yearday"]      = strftime("%j", now) + 0 | 
 
 
 
 
 
 | 56 | 
     time["timezone"]     = strftime("%Z", now) | 
 
 
 
 
 
 | 57 | 
     time["ampm"]         = strftime("%p", now) | 
 
 
 
 
 
 | 58 | 
     time["weeknum"]      = strftime("%U", now) + 0 | 
 
 
 
 
 
 | 59 | 
     time["altweeknum"]   = strftime("%W", now) + 0 | 
 
 
 
 
 
 | 60 | 
  | 
 
 
 
 
 
 | 61 | 
     return ret | 
 
 
 
 
 
 | 62 | 
 } |