Skip to content

Commit

Permalink
ivy: fix the help message for sys (date and time were swapped)
Browse files Browse the repository at this point in the history
Also add

   sys "ns"

to return the Unix time in nanoseconds.
  • Loading branch information
robpike committed Jul 30, 2023
1 parent 1d412ad commit d6118f9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions value/sys.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const sysHelp = `
"cpu": the processor timing for the last evaluation
as a vector in units of seconds:
real user(cpu) system(cpu)
"date": the current time as a vector of numbers:
"date": the current time in Unix format
year month day hour minute second
"format": the output format setting
"ibase": the input base (ibase) setting
Expand All @@ -27,7 +27,10 @@ const sysHelp = `
"obase": the output base (obase) setting
"origin": the index origin setting
"prompt": the prompt setting
"time": the current time in Unix format`
"ns": the current time in nanoseconds since
Jan 1 00:00:00 1970 UTC
"time": the current time as a vector of numbers:
year month day hour minute second`

// sys implements the variegated "sys" unary operator.
func sys(c Context, v Value) Value {
Expand Down Expand Up @@ -72,6 +75,10 @@ func sys(c Context, v Value) Value {
return Int(c.Config().Origin())
case "prompt":
return newCharVector(fmt.Sprintf("%q", c.Config().Prompt()))
case "ns":
var i big.Int
i.SetInt64(time.Now().UnixNano())
return BigInt{&i}
case "time":
date := time.Now()
y, m, d := date.Date()
Expand Down

0 comments on commit d6118f9

Please sign in to comment.