
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
github.com/davidgiffin/go-timezone-local
Works on windows, linux and macos
built-in functionality sometimes won't suffice:
zone, _ := time.Now().Zone() // try to get my time zone...
loc, _ := time.LoadLocation(zone)
fmt.Println(zone, loc) // prints e.g. CEST UTC -> obviously wrong!
localizing a date with obtained loc
will cause
panic: time: missing Location in call to Date
go get github.com/thlib/go-timezone-local/tzlocal
Open your project folder
Create a file main.go
package main
import (
"fmt"
"time"
"github.com/thlib/go-timezone-local/tzlocal"
)
func main() {
tzname, err := tzlocal.RuntimeTZ()
fmt.Println(tzname, err)
// example:
// tzname = "Europe/Berlin"
// now you can use tzname to properly set up a location:
loc, _ := time.LoadLocation(tzname)
d0 := time.Date(2021, 10, 30, 20, 0, 0, 0, loc) // DST active:
fmt.Println(d0)
// 2021-10-30 20:00:00 +0200 CEST
d1 := d0.AddDate(0, 0, 1) // add one day, now DST is inactive:
fmt.Println(d1)
// 2021-10-31 20:00:00 +0100 CET
}
Run the following commands:
go mod init example.com/yourpackage
go mod vendor
go run main.go
It should print the go runtime timezone.
Clone github.com/thlib/go-timezone-local
Change directory to go-timezone-local
cd go-timezone-local
go generate ./...
All credit goes to colm.anseo and MrFuppes for providing the following answers:
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.