mirror of
				git://git.code.sf.net/p/zsh/code
				synced 2025-10-30 17:50:58 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			64 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
| COMMENT(!MOD!zsh/datetime
 | |
| Some date/time commands and parameters.
 | |
| !MOD!)
 | |
| The tt(zsh/datetime) module makes available one builtin command:
 | |
| 
 | |
| startitem()
 | |
| findex(strftime)
 | |
| cindex(date string, printing)
 | |
| xitem(tt(strftime) [ tt(-s) var(scalar) ] var(format) var(epochtime) )
 | |
| item(tt(strftime) tt(-r) [ tt(-q) ] [ tt(-s) var(scalar) ] var(format) var(timestring) )(
 | |
| Output the date denoted by var(epochtime) in the var(format)
 | |
| specified.
 | |
| 
 | |
| With the option tt(-r) (reverse), use the format var(format) to parse the
 | |
| input string var(timestring) and output the number of seconds since the
 | |
| epoch at which the time occurred.  If no timezone is parsed, the current
 | |
| timezone is used; other parameters are set to zero if not present.  If
 | |
| var(timestring) does not match var(format) the command returns status 1; it
 | |
| will additionally print an error message unless the option tt(-q) (quiet)
 | |
| is given.  If var(timestring) matches var(format) but not all characters in
 | |
| var(timestring) were used, the conversion succeeds; however, a warning is
 | |
| issued unless the option tt(-q) is given.  The matching is implemented by
 | |
| the system function tt(strptime); see manref(strptime)(3).  This means that
 | |
| zsh format extensions are not available, however for reverse lookup they
 | |
| are not required.  If the function is not implemented, the command returns
 | |
| status 2 and (unless tt(-q) is given) prints a message.
 | |
| 
 | |
| If tt(-s) var(scalar) is given, assign the date string (or epoch time
 | |
| in seconds if tt(-r) is given) to var(scalar) instead of printing it.
 | |
| )
 | |
| enditem()
 | |
| 
 | |
| The tt(zsh/datetime) module makes available several parameters;
 | |
| all are readonly:
 | |
| 
 | |
| startitem()
 | |
| vindex(EPOCHREALTIME)
 | |
| item(tt(EPOCHREALTIME))(
 | |
| A floating point value representing the number of seconds since
 | |
| the epoch.  The notional accuracy is to nanoseconds if the
 | |
| tt(clock_gettime) call is available and to microseconds otherwise,
 | |
| but in practice the range of double precision floating point and
 | |
| shell scheduling latencies may be significant effects.
 | |
| )
 | |
| vindex(EPOCHSECONDS)
 | |
| item(tt(EPOCHSECONDS))(
 | |
| An integer value representing the number of seconds since the
 | |
| epoch.
 | |
| )
 | |
| vindex(epochtime)
 | |
| item(tt(epochtime))(
 | |
| An array value containing the number of seconds since the epoch
 | |
| in the first element and the remainder of the time since the epoch
 | |
| in nanoseconds in the second element.  To ensure the two elements
 | |
| are consistent the array should be copied or otherwise referenced
 | |
| as a single substitution before the values are used.  The following
 | |
| idiom may be used:
 | |
| 
 | |
| example(for secs nsecs in $epochtime; do
 | |
|   ...
 | |
| done)
 | |
| 
 | |
| )
 | |
| enditem()
 |