【问题标题】:postgresql - how to extract a list of past and known future offset changes for a timezonepostgresql - 如何提取时区过去和已知未来偏移更改的列表
【发布时间】:2017-07-28 20:29:33
【问题描述】:

Postgresql 非常擅长处理时区,使用经典的 tzdata 数据库。

服务器可以按照 tzdata 中的规则(偏移量、dst 变化……)在不同时区之间转换过去和未来的时间戳

对于给定的时区和给定的日期范围,当时区修改事件发生时,是否有一种简单有效的方法来提取该范围内的所有时间戳?

结果应该或多或少包含zdump linux 命令的输出。

zdump -v /usr/share/zoneinfo/America/Los_Angeles | grep 2017

Sun Mar 12 09:59:59 2017 UTC = Sun Mar 12 01:59:59 2017 PST isdst=0 gmtoff=-28800
Sun Mar 12 10:00:00 2017 UTC = Sun Mar 12 03:00:00 2017 PDT isdst=1 gmtoff=-25200
Sun Nov  5 08:59:59 2017 UTC = Sun Nov  5 01:59:59 2017 PDT isdst=1 gmtoff=-25200
Sun Nov  5 09:00:00 2017 UTC = Sun Nov  5 01:00:00 2017 PST isdst=0 gmtoff=-28800

【问题讨论】:

  • 必须在 postrgres 中吗?在应用程序代码中执行此操作可能更容易。
  • 好吧,我宁愿把所有东西都放在一个地方,并且能够轻松地进行 JOIN。

标签: postgresql timezone tzdata


【解决方案1】:
select d::date
from (
    select
        d at time zone 'America/Los_Angeles' as la,
        lead(d at time zone 'America/Los_Angeles') over (order by d) as la_,
        d 
    from generate_series (
        '2017-01-01'::timestamp,
        '2017-12-31', '1 day'
    ) gs (d)
) s
where la::time <> la_::time;
     d      
------------
 2017-03-12
 2017-11-05

【讨论】:

  • 有趣。这为您提供了日期(它是否适用于正偏移和负偏移?),但不是修改发生时的确切时间戳。在系列中使用小时/秒会有效吗?
猜你喜欢
  • 2014-12-28
  • 2015-05-18
  • 2011-09-23
  • 1970-01-01
  • 2014-12-10
  • 1970-01-01
  • 2011-10-30
  • 1970-01-01
  • 2010-10-22
相关资源
最近更新 更多