How to add timestamp in R? - r

I have a data which have the difference between the start and end time of an event. Now I want to add the difference. the problem is the difference time is in format
difference_time
_______________
00:10:00
00:30:12
01:09:09
00:09:03
01:09:30
01:09:03
00:09:08
01:00:09
09:00:01
But if I do sum(df$difference_time) it throws the error that invalid type of arguement.
I want the result to be something like below format:
51975 seconds.
Any help is appreciated
UPDATE:
I tried period_to_seconds(hms(df$difference_time)) and it works fine

period_to_seconds(hms(df$difference_time))
did the trick.

Related

BlueSky Statistics - String to date [time] issues

Trying to convert time as a string to a time variable.
Use Date/Dates/Convert String to Date...... for format I use %H:%M:%S....
Here is the syntax from the GUI
[Convert String Variables to Date]
BSkystrptime (varNames = c('Time'),dateFormat = "%H:%M:%S",prefixOrSuffix = "prefix",prefixOrSuffixValue = "Con_",data = "Dataset2")
BSkyLoadRefreshDataframe(dframe=Dataset2,load.dataframe=TRUE)
A screen shot of result is attached....
Compare variables Time [string] to Con_Time [date/time]
The hours are 2 hours out [wrong!] - the Minutes and Seconds are correct.
What am I doing wrong here?
Screen Shot
I believe you are running into a known issue with a prior release of BlueSky Statistics. This issue is fixed with the current stable release available on the download page.
The reason for this was although the time is converted correctly into the local time zone, BlueSky Statistics was reading the time zone in the local time zone and converting it to UTC.
You are probably +2 hours ahead of UTC, so you are seeing the time move 2 hrs back. Give us a couple of days to post a patch.
You can also confirm this by writing and executing the following syntax in the syntax window
Dataset2$Con_Time

Momentjs - cannot set hour and minutes in UTC

Why
moment().utc("14:30", "HH:mm").format()
gives me
2019-06-07T00:56:14Z - my local time
instead of
2019-06-07T14:30:14Z
Thank you in advance for help.
Use the moment without () like this moment.utc("14:30", "HH:mm").format()

splunk mysearchbar.timerange.val() datetime to UTC

I am using Splunk 6.2.X along with Django bindings to create a Splunk app.
To get access to the earliest/latest dates from the timerange picker, am using the following in my JS.
mysearchbar.timerange.val()
Am getting back a map where the values are in epoch format:
Object {earliest_time: 1440122400, latest_time: 1440124200}
When I convert them using moment using the following, I get different datetime than expected:
> moment.unix('1440122400').utc().toString()
"Fri Aug 21 2015 02:00:00 GMT+0000"
However, the time does not correspond to the values that have been selected on the time range picker i.e. 08/20/2015 22:00:00.000
Am not sure what the difference is getting caused by? Am sure tht the timezone is not the factor as the time difference is erratically not equivalent to derive using simple timezone add/subtract.
I was wondering if this behaviour can be explained as to how to get the Splunk epoch datetime to UTC would be helpful.
I was able to get rid of the timezone issue by performing the following:
Setting the timezone of the Splunk engine to UTC in props.conf as follows:
TZ = GMT
Setting up the CentOS (the server hosting Splunk) to UTC
Hope this helps anyone else who stumbles upon similar issues.
Thanks.

Unitils dataset - insert into sybase datetime column

I have a unitils dataset attempting to enter data into a sybase datetime column, but it errors when I try and run the unit tests.
I cannot find anything online about inserting dates, so I tried declaring it as a String in the same way as the other columns, but I get the error:
org.unitils.core.UnitilsException: Error inserting test data from DbUnit dataset for method etc etc
at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java:156)
at org.unitils.dbunit.DbUnitModule$DbUnitListener.beforeTestSetUp(DbUnitModule.java:556)
at org.unitils.core.Unitils$UnitilsTestListener.beforeTestSetUp(Unitils.java:273)
at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runBeforesThenTestThenAfters(UnitilsJUnit4TestClassRunner.java:151)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
at org.unitils.UnitilsJUnit4TestClassRunner.invokeTestMethod(UnitilsJUnit4TestClassRunner.java:95)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
at org.unitils.UnitilsJUnit4TestClassRunner.access$000(UnitilsJUnit4TestClassRunner.java:44)
at org.unitils.UnitilsJUnit4TestClassRunner$1.run(UnitilsJUnit4TestClassRunner.java:62)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.unitils.core.UnitilsException: Error while executing DataSetLoadStrategy
at org.unitils.dbunit.datasetloadstrategy.impl.BaseDataSetLoadStrategy.execute(BaseDataSetLoadStrategy.java:46)
at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java:230)
at org.unitils.dbunit.DbUnitModule.insertDataSet(DbUnitModule.java:153)
... 18 more
Caused by: org.dbunit.dataset.datatype.TypeCastException: Error casting value for table 'USER' and column 'SUSPEND_SD'
at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:202)
at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:78)
at org.unitils.dbunit.datasetloadstrategy.impl.CleanInsertLoadStrategy.doExecute(CleanInsertLoadStrategy.java:45)
at org.unitils.dbunit.datasetloadstrategy.impl.BaseDataSetLoadStrategy.execute(BaseDataSetLoadStrategy.java:44)
... 20 more
The only line inserting a date in my dataset is:
<USER ID="4" FULL_NAME="user3" SUSPEND_SD="25/12/2011 00:00" SUSPEND_ED="25/12/2013 00:00" PASSWORD="password3"/>
Can anyone help?
Thanks in advance.
Ok, it turns out it has to be in exactly the format YYYY-MM-DD HH:MM:SS", for example "2011-01-01 02:00:00".
I don't know how unitils works but assuming your dataset is editable why not change the dates to yyyy/mm/dd format.
That java stack mentions casting, and that'll be a failure getting dd/mm/yyyy to datetime I'd think.
Alternatively the middleware probably has some date config means - you can probably tell it dates are British (it might even be regional settings?)

Strange behaviour while accessing elements in an XTS

I have an XTS that is part of a list returns$sig and from that XTS, I pull out a set of elements based on some conditions and store the Index in a variable tstart.
> tstart <- index(returns$sig[which(returns$sig != lag(returns$sig,1) & returns$sig != 0)])
> length(tstart)
[1] 599
When I try and access the returns$sig XTS again with the dates in tstart, I get a XTS with a different length:
> length(returns$sig[tstart])
[1] 478
It should return something with length 599. If I try and access the XTS in a different way, I do get something of the same length:
> length(returns$sig[match(tstart,index(returns$sig))])
[1] 599
Spent hours on this and haven't found a resolution. Is there something obvious that I am doing wrong? And to make matters worse, I swear that length(returns$sig[tstart]) returned 599 yesterday and everything was working fine.
Sorry for the poorly formed question. I couldn't reproduce the error with a short example and didn't want to post all my code. I have finally figured out the issue. It seems to be related to a bug some ppl (myself included) have been reporting with XTS. All I needed to do was to specify a timezone for my system with Sys.setenv(TZ = "GMT").
For those that are interested, I am using xts_0.8-8.

Resources