Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import date-time at a specified timezone, disregard Daylight Savings Time

I have time series data obtained from a data logger that was set to one time zone without daylight savings (NZST or UTC+12:00), and the data spans a few years. Data loggers don't consider DST changes, and are synchronized to local time with/without DST (depending who deployed it).

However, when I get the data into R, I'm unable to properly use as.POSIXct to ignore DST. I'm using R 2.14.0 on a Windows computer with these settings:

> Sys.timezone()
[1] "NZDT"
> Sys.getlocale("LC_TIME")
[1] "English_New Zealand.1252"

Here are three timestamps across the spring DST change, each are spaced 1 hour apart:

> ts_str <- c("28/09/2008 01:00", "28/09/2008 02:00", "28/09/2008 03:00")
> as.POSIXct(ts_str, format="%d/%m/%Y %H:%M", tz="")
[1] "2008-09-28 01:00:00 NZST" NA
[3] "2008-09-28 03:00:00 NZDT"
> as.POSIXct(ts_str, format="%d/%m/%Y %H:%M", tz="UTC")
[1] "2008-09-28 01:00:00 UTC" "2008-09-28 02:00:00 UTC"
[3] "2008-09-28 03:00:00 UTC"

As you can see, the clocks jumped forward at 1:59 to 3:00, so 2:00 is invalid, thus NA. Furthermore, I can use tz="UTC" to get it to ignore DST changes. However, I'd rather keep the correct time zone since I have other data series recorded with DST (NZDT or UTC+13:00) that I'd like to blend in (via merge) for my analysis.

How do I configure the tz parameter on a MS Windows computer? I've tried many things, such as "NZST", "New Zealand Standard Time", "UTC+12:00", "+1200", etc., but no luck. Or do I modify some other setting?

like image 890
Mike T Avatar asked Nov 04 '11 01:11

Mike T


People also ask

Does UTC offset change with daylight savings?

The switch to daylight saving time does not affect UTC. It refers to time on the zero or Greenwich meridian, which is not adjusted to reflect changes either to or from Daylight Saving Time.

What is the function to offset the date for daylight saving Python?

dst() method which returns the daylight saving time difference at any point. If the timestamp occurs during daylight saving time, it returns a datetime. timedelta value of one hour.

How is DST date calculated?

In most of the US, DST starts on the second Sunday of March and ends on the first Sunday of November, at 2:AM both times. The second Sunday in March will always be between the 8th and the 14th inclusive. The first Sunday in November will always be between the 1st and 7th inclusive.


2 Answers

You can use tz="Etc/GMT+12":

as.POSIXct(ts_str, format="%d/%m/%Y %H:%M", tz="Etc/GMT+12")
[1] "2008-09-28 01:00:00 GMT+12" "2008-09-28 02:00:00 GMT+12"
[3] "2008-09-28 03:00:00 GMT+12"

For a full list of available timezones use,

dir(file.path(R.home("share"),"zoneinfo"), recursive=TRUE)

There are a couple of of .tab files in there which aren't timezones but hold some information, but my regex-fu isn't good enough to be able to exclude them with the pattern argument to dir.

like image 52
James Avatar answered Oct 06 '22 12:10

James


If just add 12*60*60 to that UTC derived vector, you will have local "standard" time.

like image 23
IRTFM Avatar answered Oct 06 '22 12:10

IRTFM