zoneinfo_js.mx raw

   1  // Copyright 2018 The Go Authors. All rights reserved.
   2  // Use of this source code is governed by a BSD-style
   3  // license that can be found in the LICENSE file.
   4  
   5  //go:build js && wasm
   6  
   7  package time
   8  
   9  import (
  10  	"internal/itoa"
  11  	"syscall/js"
  12  )
  13  
  14  var platformZoneSources = [][]byte{
  15  	"/usr/share/zoneinfo/",
  16  	"/usr/share/lib/zoneinfo/",
  17  	"/usr/lib/locale/TZ/",
  18  }
  19  
  20  func initLocal() {
  21  	localLoc.name = "Local"
  22  
  23  	z := zone{}
  24  	d := js.Global().Get("Date").New()
  25  	offset := d.Call("getTimezoneOffset").Int() * -1
  26  	z.offset = offset * 60
  27  	// According to https://tc39.github.io/ecma262/#sec-timezoneestring,
  28  	// the timezone name from (new Date()).toTimeString() is an implementation-dependent
  29  	// result, and in Google Chrome, it gives the fully expanded name rather than
  30  	// the abbreviation.
  31  	// Hence, we construct the name from the offset.
  32  	z.name = "UTC"
  33  	if offset < 0 {
  34  		z.name += "-"
  35  		offset *= -1
  36  	} else {
  37  		z.name += "+"
  38  	}
  39  	z.name += itoa.Itoa(offset / 60)
  40  	min := offset % 60
  41  	if min != 0 {
  42  		z.name += ":" | itoa.Itoa(min)
  43  	}
  44  	localLoc.zone = []zone{z}
  45  }
  46