How can I convert xs:dayTimeDuration to milliseconds in XPath 2.0? - xpath

I have a value of the type xs:dayTimeDuration and I want to know how many milliseconds are in this duration.
Example: 3 minutes and 5 seconds in xs:dayTimeDuration is PT3M5S and it is 185000 milliseconds.
How can I convert xs:dayTimeDuration to milliseconds in XPath 2.0?

Use
xs:dayTimeDuration('PT3M5S') div xs:dayTimeDuration('PT0.001S')

Related

Google Spreadsheet time between date - hour calculation

I am at a loss, i looked around the internet and stackoverflow but every so called solution is giving either errors or plainly don't work.
I have the following setup.
4 fields (setup in date dd-mm-yyyy, hour hh:mm:ss) seconds are not important.
start date : 7-1-2020
start hour : 23:30:00
end date : 8-1-2020
end hour : 03:50:00
What i want to happen is to calculate the diffrence in 'hours, minutes' between the end and the start date, hour. But when I calculate and change the end date to lets say 09-01-2020 it does not count the extra 24h at all.
Use Text format:
=text(A3-A1+A4-A2,"[H]:MM")
You need to format the time difference as a duration using the custom format
[h]:mm
for hours and minutes
or
[h]
for whole hours.
There are some good notes on how it works in Excel here and as far as I can tell from testing it Google Sheets is the same.
Alternatively, if I read your question as wanting to drop the minutes and seconds from the times before doing the calculation, you could use
=(B3-B1)*24+hour(B4)-hour(B2)
and just format the result as a normal number.
After alot of fiddeling and this post i came to the conclusion that the main issue was not laying within the mathematical but within the format of the cell.
By default all time values in sheets are 24h max.
So the basic formula =start - end
The time format needed should be
more date time format
elapsed hours : elapsed minutes
apply
Now you should see the correct elapsed hours and minutes

Calculate two date duration in Elastic 6.7 using painless script

I used below simple expression for getting duration:
doc['endTime'].date.millisOfDay - doc['startTime'].date.millisOfDay
But the problem starts when, endTime crosses the startTime day.
Example: If startTime is 23:50 and endTime for the same is 00:12, we
crossed by midnight, which changes the date as well.
In that way I am getting absolutely wrong duration, except all the scenarios when both time lies with in the same day result is as expected.
Help on how exactly i can make this.
You should simply subtract the absolute milliseconds value since the epoch (instead of milliseconds since the start of the day):
doc['endTime'].date.millis - doc['startTime'].date.millis

Does steady_clock::now return seconds?

I am trying to figure out what the value of t is ? Is it seconds or milliseconds ? The steady_clock reference does not mention the unit used.
auto t = std::chrono::steady_clock::now() / 1000;
auto p = t/1000;
I am thinking now() returns seconds and t is in milliseconds and p is in microseconds. Let me know if I am getting this right ?
It's std::chrono::time_point<std::chrono::steady_clock> (the documentation on CppReference is generally better quality).
Guessing your next question — to convert from that to seconds you would use time_since_epoch() (the documentation has an example of extracting a dimension-free number of seconds from it), or alternatively as (now - epoch) / 1_second
Unit of value returned by std::chrono::steady_clock::now() is not defined by standard (it is general value of type std::chrono::time_point).
The resolution of the std::chrono::time_point (it stores a value of type Duration indicating the time interval from the start of the Clock's epoch) is implementation dependent (platforms/compiler), and you shouldn't rely on it.
To get a desired unit, you can easily convert the time_point to a value in seconds, milliseconds, etc. by duration casting:
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
(time_since_epoch() returns a duration representing the amount of time between *this and the clock's epoch).

microseconds epoch time parsing using strptime

I am using fluentbit for sending logs and the logs have a timestamp like:
__REALTIME_TIMESTAMP : <micro seconds from epoch>
example -
__REALTIME_TIMESTAMP : 1528118184711009
Fluentbit uses strptime to parse the time string. But as I see in the documentation of strptime, I do not see a format string that does the parsing for microseconds from epoch or milliseconds from epoch.
I can only specify the format string in fluentbit.
I was guessing it like "%10s" for only taking the first 10 digits but it doesn't works.
Any help is appreciated.
Thanks in advance.
For posterity:
The %s works fine for even microseconds. It only takes the required number of digits if there is more precision given.

How to get NSEvent timestamp in milliseconds?

#property(readonly) NSTimeInterval timestamp;
denotes the time when the event occurred in seconds since system startup. I want to compare the timestamps of two events but their differences can also be in milliseconds. So, is there any way to get the timestamp of an event in milliseconds. I know I can use the methods mentioned in this SO question but would that be appropriate to use for events ?
If you want milliseconds you can multiply by 1000.0 but you can compare without multiplying. Documentation of NSTimeInterval:
typedef double NSTimeInterval;
NSTimeInterval is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.

Resources