Skip to content

Commit

Permalink
simplify conversion using time_add
Browse files Browse the repository at this point in the history
* this takes care of all the offset issues
  • Loading branch information
jefferis committed Aug 4, 2024
1 parent 098bc17 commit e002bb2
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions R/ReadIgorBinary.R
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,9 @@ read.pxp<-function(pxpfile,regex,ReturnTimeSeries=FALSE,Verbose=FALSE,
# results regardless of the local timezone of the test machine
.convertIgorDate<-function(dateval, tz=""){
igor_origin=ISOdatetime(1904,1,1,hour=0,min = 0, sec=0, tz=tz)
igor_origin_utc=ISOdatetime(1904,1,1,hour=0,min = 0, sec=0, tz='GMT')
origin_offset=as.numeric(igor_origin)-as.numeric(igor_origin_utc)

dateval=dateval+as.numeric(igor_origin)
res=as.POSIXct(dateval, tz = tz)
# this takes the same clock time (ie hms) but switches time zone, thereby
# changing the moment in time
res_utc=timechange::time_force_tz(res, tz = 'GMT')
res_offset=as.numeric(res)-as.numeric(res_utc)

# DST correction
dst_correction=origin_offset-res_offset
res=res-dst_correction
# this takes care of tz offset differences between the actual date and the origin
# e.g. because date is during daylight savings (but origin was not)
res=timechange::time_add(igor_origin, second = dateval)
res
}

Expand Down

0 comments on commit e002bb2

Please sign in to comment.