home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuawk.zip / awklib / eg / lib / gettime.awk < prev    next >
Text File  |  1997-03-15  |  3KB  |  62 lines

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