Ns time

From AOLserver Wiki
Jump to navigation Jump to search

<manpage>ns_time</manpage>

NAME

ns_time - Perform various time-related functions

SYNOPSIS

ns_time ?option? ?arg arg ...?

DESCRIPTION

This command provides various time-related functions. The legal options (which may be abbreviated) are:
  • ns_time adjust time
Adjusts time so that it is within the valid range of values for a time. (TODO: Figure out how this is actually useful.)
  • ns_time diff time1 time2
Computes the time difference between time1 and time2. It does this by subtracting time2 from time1 and returns a string in "sec:usec" format. Put the later time first to get the proper result.
  • ns_time get
Returns the current time in "sec:usec" format.
  • ns_time incr time sec ?usec?
Increments time by sec seconds and optionally usec microseconds. Returns a string in "sec:usec" format. Note that ns_time incr will result in negative seconds if given too large a value of microseconds (like an hour). Use a proc like this to work around:
   proc ns_time_incrmicroseconds {microseconds {time 0}} {
      set secondsList [split [expr {$microseconds/1000000.0}] .]
      set microseconds [expr int(0.[lindex $secondsList 1] * 1000000)]
      return [ns_time incr $time [lindex $secondsList 0] $microseconds]
   }
   ns_time_incrmicroseconds usec time
  • ns_time make sec ?usec?
Returns a string in the form "sec:usec". usec defaults to zero. If usec is zero, the colon and usec are not returned. If sec is zero, however, it is returned as part of the time string. Note that ns_time make will generate negative seconds if given too large a value of microseconds (like an hour). Use ns_time_incrmicroseconds usec (above) without specifying time.


  • ns_time seconds time
Parses a time in "sec:usec" format and returns the seconds portion.
  • ns_time microseconds time
Parses a time in "sec:usec" format and returns the microseconds portion. It assumes zero microseconds if time only contains seconds.

NOTES

All times are relative to 00:00:00 UTC, January 1, 1970 aka the Unix epoch. ns_time called with no option returns the current time in seconds.

EXAMPLES

   % ns_time
   1087006685
   % set time [ns_time get]
   1087013247:598897
   % ns_time seconds $time
   1087013247
   % ns_time microseconds $time
   598897
   % set time2 [ns_time incr $time 5 30]
   1087013252:598927
   % ns_set diff $time2 $time
   5:30
   % set time3 [ns_time make 1087013240 598890]
   1087013240:598890
   % ns_time diff $time $time3
   7:7
   % ns_time diff $time3 $time
   -8:999993
   % set time3 [ns_time incr $time3 7 7]
   1087013247:598897
   % ns_time diff $time $time3
   0

SEE ALSO

ns_fmttime, ns_gmtime, ns_httptime, ns_localtime, ns_parsehttptime, ns_parsetime