Skip to content

Commit

Permalink
joker.time/format
Browse files Browse the repository at this point in the history
  • Loading branch information
candid82 committed Mar 9, 2018
1 parent 748fc4e commit 914efc6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions std/time.joke
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@
:go "int(time.Until(t))"}
[^Time t])

(defn ^String format
"Returns a textual representation of the time value formatted according to layout,
which defines the format by showing how the reference time, defined to be
Mon Jan 2 15:04:05 -0700 MST 2006
would be displayed if it were the value; it serves as an example of the desired output.
The same display rules will then be applied to the time value.."
{:added "1.0"
:go "t.Format(layout)"}
[^Time t ^String layout])

(defn ^Double hours
"Returns the duration (passed as a number of nanoseconds) as a floating point number of hours."
{:added "1.0"
Expand Down
25 changes: 25 additions & 0 deletions std/time/a_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ var add_ Proc = func(args []Object) Object {
return NIL
}

var format_ Proc = func(args []Object) Object {
c := len(args)
switch {
case c == 2:

t := ExtractTime(args, 0)
layout := ExtractString(args, 1)
res := t.Format(layout)
return MakeString(res)

default:
PanicArity(c)
}
return NIL
}

var from_unix_ Proc = func(args []Object) Object {
c := len(args)
switch {
Expand Down Expand Up @@ -249,6 +265,15 @@ timeNamespace.InternVar("add", add_,
NewListFrom(NewVectorFrom(MakeSymbol("t"), MakeSymbol("d"))),
`Returns the time t+d.`, "1.0"))

timeNamespace.InternVar("format", format_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("t"), MakeSymbol("layout"))),
`Returns a textual representation of the time value formatted according to layout,
which defines the format by showing how the reference time, defined to be
Mon Jan 2 15:04:05 -0700 MST 2006
would be displayed if it were the value; it serves as an example of the desired output.
The same display rules will then be applied to the time value..`, "1.0"))

timeNamespace.InternVar("from-unix", from_unix_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("sec"), MakeSymbol("nsec"))),
Expand Down

0 comments on commit 914efc6

Please sign in to comment.