dst

Python 3.9: Construct DST valid timestamp using standard library

☆樱花仙子☆ 提交于 2021-02-19 04:35:07
问题 I would like to contruct DST-valid timestamps only using the standard library in Python 3.9 and was hoping this was possible with this version. In my timezone "Europe/Berlin", the DST crossings for 2020 are: 2020-03-29 at 02:00 the clock switches to 03:00 (there is no hour 2!) 2020-10-25 at 03:00 the clock switches back to 02:00 (the hour 2 exists two times!) My script yields the following output: MARCH 2020-03-29 01:59:00+01:00 CET plus 1 h: 2020-03-29 02:59:00+01:00 CET (should be 03:59:00

Safe handling of daylight savings (or any other theoretical non-constant offset) while calculating durations between DateTimes

眉间皱痕 提交于 2021-02-15 07:33:30
问题 I know this isn't the first time this topic has been brought up even in the past 24 hours, but I'm surprised that I have not come across one clear / best practices solution to this problem. The problem also seems to contradict what I thought was a no-brainer design decision to save all dates in UTC. I'll try to state the problem here: Given two DateTime objects, find the duration between them while accounting for daylight savings. Consider the following scenarios: UtcDate - LocalDate where

Best practice for adding/subtracting from universal or local DateTime

☆樱花仙子☆ 提交于 2021-02-10 04:37:15
问题 I'm trying to add a wrapper around DateTime to include the time zone information. Here's what I have so far: public struct DateTimeWithZone { private readonly DateTime _utcDateTime; private readonly TimeZoneInfo _timeZone; public DateTimeWithZone(DateTime dateTime, TimeZoneInfo timeZone) { _utcDateTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified), timeZone); _timeZone = timeZone; } public DateTime UniversalTime { get { return _utcDateTime; } }

Best practice for adding/subtracting from universal or local DateTime

寵の児 提交于 2021-02-10 04:36:37
问题 I'm trying to add a wrapper around DateTime to include the time zone information. Here's what I have so far: public struct DateTimeWithZone { private readonly DateTime _utcDateTime; private readonly TimeZoneInfo _timeZone; public DateTimeWithZone(DateTime dateTime, TimeZoneInfo timeZone) { _utcDateTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified), timeZone); _timeZone = timeZone; } public DateTime UniversalTime { get { return _utcDateTime; } }

When is it ok to store datetimes as local time rathen than UTC?

主宰稳场 提交于 2021-02-04 16:47:37
问题 This is a question similar to this one. I'm really tempted to store datetimes in my app as local time rather than as UTC (which is considered a best practice). In the app I have a number of events happening, each assigned to a given location. Always when I display them to the user, I want to show the local time of the event. I.e.: ==================================================================================== Event time (with TZ) | As UTC | As local time | To be displayed | =============

When is it ok to store datetimes as local time rathen than UTC?

久未见 提交于 2021-02-04 16:47:22
问题 This is a question similar to this one. I'm really tempted to store datetimes in my app as local time rather than as UTC (which is considered a best practice). In the app I have a number of events happening, each assigned to a given location. Always when I display them to the user, I want to show the local time of the event. I.e.: ==================================================================================== Event time (with TZ) | As UTC | As local time | To be displayed | =============

Dates in Safari appear off by one using Intl.DateTimeFormat with en-US locale

大憨熊 提交于 2021-01-29 17:52:25
问题 It looks like Safari's implementation of Int.DateTimeFormat assumes that the second Sunday in March will ALWAYS be the DST time cutoff which is not correct as prior to 2007 it was the first Sunday in April. It also appears that this affects the other end as well when DST ends. PS: This code is being run in Indiana, USA which is in the eastern time zone (GMT-4) More specifically... 2007 and newer: correctly for all dates. 2006: incorrectly for dates between the second Sunday in March and first

R - Dplyr grouping with Daylight Saving Time

别等时光非礼了梦想. 提交于 2021-01-29 15:56:50
问题 I have a DataFrame f with data at a 10 mins time step like so: DateTime id value name 2015-01-01 00:00:00 40497 0 HY 2015-01-01 00:00:00 51395 589 HY 2015-01-01 00:10:00 51395 583 HY 2015-01-01 00:10:00 40497 0 HY 2015-01-01 00:20:00 51395 586 HY 2015-01-01 00:20:00 40497 0 HY 2015-01-01 00:30:00 40497 0 HY 2015-01-01 00:30:00 51395 586 HY 2015-01-01 00:40:00 40497 0 HY The columns id and name are not relevant to what I want to do. The type of the DataFrame is as follows: 'data.frame': 9510

Pandas convert UNIX time to multiple different timezones depending on column value

淺唱寂寞╮ 提交于 2021-01-28 11:21:41
问题 I have a pandas dataframe with UNIX timestamps (these are integers and not time objects). The observations occur in multiple geographic locations, and therefore multiple timezones. I'd like to convert the UNIX timestamp into local time (in a new column) for each of these timezones, based on the geography of the observation (this information is in a column of the dataframe). Simple working example: Creating the dataframe: c1=[1546555701, 1546378818, 1546574677, 1546399159, 1546572278] c2=[

How to find out the next time when the clock will be adjusted for Daylight Saving?

六眼飞鱼酱① 提交于 2021-01-27 17:26:21
问题 I'm curious, if there's any way to find out the UTC date/time when the next Daylight Saving adjustment will take place? Something akin to what Windows reports (see circled): 回答1: This information is provided in Windows by the EnumDynamicTimeZoneInformation function. See http://msdn.microsoft.com/en-us/library/windows/desktop/hh706893%28v=vs.85%29.aspx 回答2: There is a database that has code and data: http://www.iana.org/time-zones 回答3: I don't think there's a specific API for this. I would