Does steady_clock::now return seconds? - c++11

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).

Related

Measure elapsed time from fixed datetime

I am trying to measure how many minutes have elapsed from the time I turn my code from a fixed time, lets say 8:30 am of that day. If I turn my code on at 12am it should see that 210 minutes have elapsed. Any suggestions would help greatly. Thank you
You can import the datetime module, which has a class with the same name, with method datetime.datetime.now().
This returns an object representing the time when it is called.
This object has the method replace(), which can be used to 'change' the time to 8:30, if you call it like so - replace(hour=8, minute=30).
You can then create another similar object but without replacing the time, then you can simply subtract the first from the second to get the elapsed time as a datetime object.
This will then have elapsed_time.seconds to give you the time change in seconds, which can be divided by 60 if you want for the time in minutes.
Example
import datetime
time_A = datetime.datetime.now()
time_A = time_A.replace(hour=8, minute=30)
time_B = datetime.datetime.now()
elapsed_time = time_B - time_A
print(elapsed_time.seconds, "seconds have passed since 8:30 this morning")
If you wanted this for a specific timezone, you can add or subtract the offset from your current timezone. So if you are for example, 5 hours ahead of CST, you can have it get the difference from 3:30 instead.

How to see what value is being calculated pine Editor

I have the following script running with the intention of closing a trade after it has been open for a period of 4 days since the trade was taken.
TimeDiff = time - time[1]
MinutesPerBar = TimeDiff / 60000
//calcuates how long one bar is in minutes
BarsSinceSwingLongCondition = barssince(SwingLongCondition)
// Calculates how many bars have passed since open of trade
CurrentSwingTradeDuration = BarsSinceSwingLongCondition * MinutesPerBar
//calculates the duration that the trade has been opened for (minutes*number of bars)
MaximumSwingTradeDuration = 4*1440
// Sets maximum trade duration. Set at 4 Days in minutes
SwingLongCloseLogic3 = CurrentSwingTradeDuration > MaximumSwingTradeDuration
// Closes trade when trade duration exceeds maximum duration set (4days)
The close logic however isn't executing when I run the strategy as i have trades open for longer than the maximum duration.
Is there any way to see what value each element of the formula is calculating so that I can see where the error is (i suspect it could be the time element). Or can anyone see where I am going wrong in the code?
The fastest way to achieve that is using the plotchar function, which would show the values in the data-window on mouse-over on each bar. The user manual contains several other techniques available for debugging.

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

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.

How to specify time in kaltura api

I am trying to call liveReport service of kaltura but I m not sure how to specify time in the request filters. It asks time to be in int format but when i canver time in milli seconds I get long value, but API is expecting int value.
can anyone provide help in this?
If you are referring to livereports.getreport service then fromTime & toTime properties expect an integer timestamp in seconds. You can also provide a timestamp that is lower then 315360000 seconds and it will be treated relative to NOW, so -1440 will be converted to NOW - 1440
Seems like other report services are expecting an integer that is created using conversion of date format YYYYMMDD to integer, so for May 18th, 2015 you would send 20150318.

Resources