go - 如何确定夏令时是否有效?
问题描述
我正在尝试为 time.Time 编写一个 isDST 函数,但是我不确定如何去做。问题是时间包中的Location类型没有导出区域信息(其中包含isDST bool)
见下文摘录。有没有办法得到这些信息?
// A Location maps time instants to the zone in use at that time.
// Typically, the Location represents the collection of time offsets
// in use in a geographical area. For many Locations the time offset varies
// depending on whether daylight savings time is in use at the time instant.
type Location struct {
name string
zone []zone
tx []zoneTrans
// The tzdata information can be followed by a string that describes
// how to handle DST transitions not recorded in zoneTrans.
// The format is the TZ environment variable without a colon; see
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html.
// Example string, for America/Los_Angeles: PST8PDT,M3.2.0,M11.1.0
extend string
// Most lookups will be for the current time.
// To avoid the binary search through tx, keep a
// static one-element cache that gives the correct
// zone for the time when the Location was created.
// if cacheStart <= t < cacheEnd,
// lookup can return cacheZone.
// The units for cacheStart and cacheEnd are seconds
// since January 1, 1970 UTC, to match the argument
// to lookup.
cacheStart int64
cacheEnd int64
cacheZone *zone
}
// A zone represents a single time zone such as CET.
type zone struct {
name string // abbreviated name, "CET"
offset int // seconds east of UTC
isDST bool // is this zone Daylight Savings Time?
}
解决方案
推荐阅读
- google-cloud-platform - Google PubSub / Gmail Webhook:发送电子邮件时始终从 PubSub 接收多个 POST 请求
- android - 改造多部分嵌套对象
- node.js - 我的 nodejs 脚本无法发送长消息
- angular - 为什么 switchMap 不取消之前的观察者?
- javascript - 使用 JavaScript 在其他标签之间动态插入 HTML 标签
- html - 是否可以使用一个复选框过滤两个输入值?
- c# - 来自 kernel32 的 DllImport LoadLibrary 和 LoadLibraryEx 适用于 .NET Framework 4.0 但不适用于 4.5+
- python - 在 R 脚本 (rpy2) 中使用来自 python 的数据在 python 中运行 R 脚本
- azure - 无法使用 Microsoft Graph 重置本地密码
- python - 元编程组合学