library(dbMapR)
Time stamping the time of row insertion is required to look for any merge conflict, when that row is to be updated at a later time. It becomes more relevant in a web based, multiple access and asynchronous database, where multiple users are accessing and changing a particular row in the database. R does not have any robust timestamp mechanism. Below, I give the details of using the time stamping mechanism built for this package.
Timestamps are basically a character
with following specific format, to which a class
attribute has been added to t_stamp
.
yyyymmddhhmmss{may be a decimal mark followed by upto 6 digits}@@Olson_compatible_timezone
Example: 20151030123634.998@@UTC
cur_timestamp
We can make current timestamp using cur_timestamp
function. It is the only way to create a timestamp (of t_stamp
class). This makes sure that we cannot make timestamps corresponding to any other time point other than current time point. cur_timestamp
function uses Sys.time
function to get the current time point. We will have to add a time zone (through tz
parameter), which should be one of the names mantioned in OlsonNames()
function. Do check OlsonNames()
to see for the valid tz
names.
as.character
coerces the t_stamp
object to character
. The timestamp is stored in database as character
.
as.POSIXct
coerces the t_stamp
object to POSIXct
class.
t_stamp.character
function coerces a character
object into a t_stamp
object given the format is conforming with t_stamp
class as checked by the utility function check_format_tstamp
.
%earlier%
, %later%
and %same_time%
are the function which compares two t_stamp
objects for their chronological order. They return boolean
value.
ts1 <- cur_timestamp(digits = 3L, tz = "Asia/Kolkata")
as.POSIXct(ts1) # keep default tz as.POSIXct(ts1, tz = "UTC") # changing tz to UTC
ts2 <- cur_timestamp(tz = "UTC") ts3 <- cur_timestamp() ts2 %later% ts3 # TRUE
ts2
is occuring before ts3
, but it is occuring at UTC
, whereas ts3
is occuring at Asia/Kolkata
time zone (UTC - 5.5 hours). So, ts2
is occuring later than ts3
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.