File: time_inexternalization.go

package info (click to toggle)
golang-github-gopherjs-gopherjs 0.0~git20170927.0.4152256-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,468 kB
  • sloc: cpp: 91; makefile: 7
file content (19 lines) | stat: -rw-r--r-- 663 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package main

import (
	"time"

	"github.com/gopherjs/gopherjs/js"
)

var _ = time.Sleep // Force "time" package to be imported but let time.Time and time.Unix be DCEed since they're not used.

func main() {
	// Excercise externalization of Go struct (with its special handling of time.Time).
	js.Global.Get("console").Call("log", struct{ S string }{"externalization ok"})

	// Excercise internalization of JavaScript Date object (with its special handling of time.Time).
	date := js.Global.Get("Date").New("2015-08-29T20:56:00.869Z").Interface()
	js.Global.Set("myDate", date)
	js.Global.Get("console").Call("log", js.Global.Get("myDate").Call("toUTCString"))
}