Product: TIBCO Spotfire®
Examples of time zone manipulation with POSIXct objects using TERR core functions
This article presents example commands that can be adapted for use in a Spotfire data function's TERR script to adjust the time zone of a POSIXct column in an input data set, using core functions in TERR.
(1) The first example changes the timezone label without shifting the date and time.
(2) The second example shifts the date and time without changing the timezone label.
(3) The third example does both.
~~~
# Examples of time zone manipulation
# with objects of class "POSIXct"
# using core functions in TERR:
# (0) This creates an example date-time group (DTG) with the machine's local time zone:
TestDTG <- Sys.time()
class(TestDTG)
TestDTG
# (1) This changes the timezone label to "UTC" without shifting the date and time:
RelabeledTestDTG <-
as.POSIXct(as.character(TestDTG), tz = "UTC")
RelabeledTestDTG
# (2) This shifts the date and time to the "UTC" time zone without changing the timezone label:
ShiftedTestDTG <-
as.POSIXct(format(TestDTG, tz = "UTC", usetz = TRUE))
ShiftedTestDTG
# (3) This does both:
ShiftedAndRelabeledTestDTG <-
as.POSIXct(
as.character(
as.POSIXct(format(TestDTG, tz = "UTC", usetz = TRUE))),
tz = "UTC")
ShiftedAndRelabeledTestDTG
Demonstration in a TERR Console session:
Copyright (C) 2011-2019 TIBCO Software Inc. ALL RIGHTS RESERVED
TIBCO Enterprise Runtime for R version 5.0.0 for Microsoft Windows 64-bit
Type 'help()' for help.
Type 'q()' to quit.
>
>
> # Examples of time zone manipulation
> # with objects of class "POSIXct"
> # using core functions in TERR:
>
>
> # (0) This creates an example date-time group (DTG) with the machine's local time zone:
>
> TestDTG <- Sys.time()
>
> class(TestDTG)
[1] "POSIXct" "POSIXt"
>
> TestDTG
[1] "2019-03-01 17:08:21 PST"
>
>
> # (1) This changes the timezone label to "UTC" without shifting the date and time:
>
> RelabeledTestDTG <-
+ as.POSIXct(as.character(TestDTG), tz = "UTC")
>
> RelabeledTestDTG
[1] "2019-03-01 17:08:21 UTC"
>
>
> # (2) This shifts the date and time to the "UTC" time zone without changing the timezone label:
>
> ShiftedTestDTG <-
+ as.POSIXct(format(TestDTG, tz = "UTC", usetz = TRUE))
>
> ShiftedTestDTG
[1] "2019-03-02 01:08:21 PST"
>
>
> # (3) This does both:
>
> ShiftedAndRelabeledTestDTG <-
+ as.POSIXct(
+ as.character(
+ as.POSIXct(format(TestDTG, tz = "UTC", usetz = TRUE))),
+ tz = "UTC")
>
> ShiftedAndRelabeledTestDTG
[1] "2019-03-02 01:08:21 UTC"
>
>
Disclaimer:
The code in this article is only a sample to be used as a reference. It is not intended to be used "As Is" in a Production environment. Always test in a Development environment. Make modifications to the code in accordance with your implementation specifications that best suit your business requirements. Refer to the reference(s) cited in this article for usage of the functions and methods used in the code.
Refer to the KB article# 000031003 for background information on how the Spotfire data function framework transfers date/time information between Spotfire and TIBCO Enterprise Runtime for R (TERR)
Comments
0 comments
Article is closed for comments.