Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 721 Bytes

README.md

File metadata and controls

35 lines (24 loc) · 721 Bytes

isdst

A golang helper to determine if a time in a location is in daylight savings time or not.

Why?

Unlike other languages, go doesn't expose the ability to determine if the time is in DST or not.

See proposal: time: add Time.IsDST() bool method #42102

How to use?

package main

import (
	"fmt"
	"time"

	"github.com/ace-teknologi/isdst"
)

func main() {
	loc, _ := time.LoadLocation("Australia/Broken_Hill")

	// DST
	t := time.Date(2020, time.January, 1, 0, 0, 0, 0, loc)
	fmt.Printf("Is daylight savings? %t", isdst.IsDST(t))

	// Non-DST
	t := time.Date(2020, time.June, 1, 0, 0, 0, 0, loc)
	fmt.Printf("Is daylight savings? %t", isdst.IsDST(t))
}