Doing math on dates ruby (json parsed date string) Syntax error - ruby

I have parsed a date in json like below
DateTime.parse(parsed["LastTimeReportGenerated"])
Now I'm trying to do Time.now-DateTime.parse(parsed["LastTimeReportGenerated"])
Whitout success. Getting the error message
scheduler caught exception:
can't convert DateTime into an exact number
What is the correct syntax? Sorry for this simple question but could't find an obvious answer to this.

The --Method of the Time object only accepts another Time object or a number (seconds) to subtract. You are giving a DateTime object, which can be converted to a Time object:
Time.now-DateTime.parse(parsed["LastTimeReportGenerated"]).to_time

Related

Alteryx Convert String to Time

I have a column of times in ALteryx like the following:
Time
=====
8:05 AM
8:07 AM
8:11 AM
8:12 AM
8:16 AM
...
They are currently stored as a String, but I want to convert them to the Time format. So far, I have tried using the LEFT and TRIM function to isolate the time itself as such:
Trim(Left([Time], 5)," ")
However, when I try to convert this to a Time datatype, I receive type conversion errors. How can I convert something like 8:46 AM from a String to a Time datatype in Alteryx?
I did some more digging and trying different things out, and I was able to figure it out. For the reference of others, here is what I did:
DateTimeParse([VisitTime] + " " + [PartofDay],"%I:%M %P")
Where [VisitTime] is the time expressed like 8:30 and [PartofDay] is AM or PM.
After this, I used a Select tile to change the datatype from String to Time without type conversion errors.

Perform add/subtract hour/min from date time in freemaker

I am new to freemarker.
In freemarker, I would like to perform arithmetic expression on DateTime as follows:
${triggerTimestamp}-1h
But this is not working. Could anyone please help here?
FreeMarker doesn't do date/time arithmetic out of the box (as of 2.3.30 at least). It's expected that the data-model (context) contains the values that you actually want to display. One can implement some helper method in Java though.
You'll want to explore converting the date into unix/epoch time. If you add ?long to the end of the variable you'll convert the datetime into epoch time (which is in seconds) then do math and convert it back to a date. Your example would be
${(triggerTimestamp?long - 1 * 1000 * 60 * 60)?number_to_datetime?string.iso}

Jmeter give timestamp value in exponential format. How to convert it to number?

I used the ${__time()) function to convert the current time into a timestamp value in seconds.
The result I got was formatted like 1.543425678e9 instead of 1543425678.
My API doesn't accept this format. Can anyone help me out here?
example of setup function and store as variable
result in debug postprocessor:
time=1557263114733
Can you describe more detail about how you are using this function? Where are you seeing the output in the incorrect format?

Time getting printed as '0x814ff30'

Learning go lang. Might be a basic question.
I have an time.Time object and I wanted to get the epoch time for it. What I write to get that is :
fmt.Println(startTime.Unix)
where startTime is an object of time.Time. Now, I would have expected it to print some big number, something as, 1257894000, but what I get is : 0x814ff30.
Did not understand why? Would be happy to write more in case it is not clear.
Use time.Unix() function
fmt.Println(time.Now().Unix())
//1479454089

Arel -- how to convert column to current timezone & truncate milliseconds

I've been trying to find detailed Arel documentation, but in vain. Finally I tried digging into the source code and figured ou
The following works (note the to_sql in the end):
Arel::Nodes::NamedFunction.new('to_char', Audit.arel_table[:created_at], 'dd-mm-yyyy').to_sql
And, the following works:
tzdate = Arel::Nodes::InfixOperation.new('at time zone', Arel::Nodes::InfixOperation.new('at time zone', Audits.arel_table[:created_at], 'gmt'), Time.zone.tzinfo.name)
The following, does NOT work (note the to_sql in the end) due to TypeError: Cannot visit Arel::Nodes::InfixOperation:
Arel::Nodes::NamedFunction.new('to_char', [tzdate, 'dd-mm-yyyy']).to_sql
Can anyone tell me what is happening here?
There are two issues here:
You need to wrap the date format string with Arel.new('dd-mm-yyyy') (which produces an Arel::Nodes::SqlLiteral).
The time zone strings need to be quoted (e.g. Arel::Nodes::Quoted.new('UTC')). See https://github.com/rails/arel/issues/323

Resources