R/convertTime.R

Defines functions convertTime

# Companion function to readNWISodbc to convert dates to proper time zone
convertTime <- function(datetime,timezone,daylight){
        
        datetime <- as.POSIXct(datetime, tz="GMT")
        ##Format date times to posixct with timezone, NWIS has 4 slots for characters followed by a tab, so for 3 letters you need 1 space and 1 tab after
        offsetLibrary <- setNames(c(00,
                                    -03.5,
                                    -04,
                                    -05,
                                    -06,
                                    -07,
                                    -08,
                                    -09,
                                    -10,
                                    -11,
                                    -12,
                                    +12,
                                    +12,
                                    +12,
                                    +11,
                                    +10,
                                    +10,
                                    +10,
                                    +10,
                                    +09.5,
                                    +09.5,
                                    +09.5,
                                    +09,
                                    +09,
                                    +08.5,
                                    +08,
                                    +08,
                                    +08,
                                    +07.5,
                                    +07,
                                    +06,
                                    +05,
                                    +04,
                                    +03.5,
                                    +03,
                                    +02,
                                    +02,
                                    +01,
                                    +01,
                                    +01,
                                    +01,
                                    +01,
                                    +01,
                                    +01,
                                    +01,
                                    +01,
                                    +01,
                                    00,
                                    -01,
                                    -02,
                                    -03,
                                    -03.5,
                                    +04.5), 
                                  c("UTC   ",
                                    "NST   ",
                                    "AST   ",
                                    "EST   ",
                                    "CST   ",
                                    "MST   ",
                                    "PST   ",
                                    "AKST  ",
                                    "HST   ",
                                    "ZP-11 ",
                                    "IDLW  ",
                                    "IDLE  ",
                                    "NZST  ",
                                    "NZT   ",
                                    "ZP11  ",
                                    "AEST  ",
                                    "EAST  ",
                                    "GST   ",
                                    "LIGT  ",
                                    "ACST  ",
                                    "CAST  ",
                                    "SAT   ",
                                    "JST   ",
                                    "KST   ",
                                    "MT    ",
                                    "AWST  ",
                                    "CCT   ",
                                    "WST   ",
                                    "JT    ",
                                    "WAST  ",
                                    "ZP6   ",
                                    "ZP5   ",
                                    "ZP4   ",
                                    "IT    ",
                                    "BT    ",
                                    "EET   ",
                                    "IST   ",
                                    "CET   ",
                                    "DNT   ",
                                    "DST   ",
                                    "FST   ",
                                    "MET   ",
                                    "MEWT  ",
                                    "MEZ   ",
                                    "NOR   ",
                                    "SET   ",
                                    "SWT   ",
                                    "WET   ",
                                    "WAT   ",
                                    "ZP-2  ",
                                    "ZP-3  ",
                                    "NFT   ",
                                    "AFT   "))
        offset <- unname(offsetLibrary[timezone]) * 60 * 60
        daylight.offset <- ifelse (daylight == "Y", 60*60,0)
        
        date.adj <- datetime + offset + daylight.offset
        return(date.adj)
}
USGS-R/WQ-Review documentation built on Nov. 12, 2019, 9:51 a.m.