get time and date using cron expression in golang - go

i'm currently looking for a solution for sometimes now,
i have this cron expression
time := '0 3,10,16,22 * * ?'
and i need to parse this into date and compare it to get a result
what my goal is to get time data from the time var and compare it,
if the time is not in between 00:00 and 00:06 it will return bool false
i understand for comparison i can use if clause but,
how to parse this cron expression and turn it into date solution were not found yet.
i've been reading cron package in godoc for sometimes and dont find it yet maybe i'm missing something?
any kind of solution or input were appreciated thanks!

You could use the package cronexpr from aptible/supercronic:
import "github.com/aptible/supercronic/cronexpr"
import "time"
nextTime := cronexpr.MustParse("0 3,10,16,22 * * ?").Next(time.Now())
Now that you have the next time, you can check if it is between 00:00 and 00:06.

Related

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}

Spring Cron Nth weekday

I was working on a project and I need to save cron expressions on either a weekly or monthly basis. Monthly crons are created on a nth day of the week. I am using cron-utils to create the cron, and found on this article that Spring Cron supports an nth day of the week. However as I have written the code, I have found little to no support for the nth day of the week using a hash. I have searched the internet and have not found a definitive answer as to whether or not spring supports the nth day of the week. So, does Spring Cron support the nth day of the week or not?
Before you answer to not add the tag, just think I want something to run "every 2nd Wednesday of each month".
I just checked, and the feature is supported by Spring, and cron-utils as well. Below the appropriate code:
import org.springframework.scheduling.support.CronExpression;
CronExpression.parse("0 0 0 ? * WED#2");
This would run the cron the second Wednesday in the month at midnight. A similar example is provided in the docs.
In cron-utils you can parse the same expression with the following code:
import com.cronutils.model.CronType;
import com.cronutils.model.definition.CronDefinitionBuilder;
CronParser parser = new CronParser(
CronDefinitionBuilder.instanceDefinitionFor(CronType.SPRING)
);
parser.parse("0 0 0 ? * WED#2");

How to get current date -1 (yesterday) in DataStage?

Hello i've been working on how to get yesterday date in DataStage?
CurrentDate()-1
When i compile the job, it gave me an error.
So how should i do to get the yesterday date?
btw that code i'm doing it in the Transformer stage
Assuming you are using the parallel engine in DataStage - this could be a solution
DateOffsetByComponents
DateOffsetByComponents(CurrentDate(), 0, 0, -1)
As the last parameter is the day part and -1 would substract a day
Convert the date into a date type, then you can add or subtract days.
You can use IConv to convert a string into a datastage internal date format. Then you can perform addition/subtraction on the date. Then use OConv to convert the variable back to string format.
If this is done in a transformer stage, you need to do this all in one statement:
OConv(Iconv(VDate ,"D/YMD[4,2,2]") - 1), "D/YMD[4,2,2]")
Hope this helps.
In a parallel Transformer stage, I'd use DateFromDaysSince() function. Use current date function as the base, and -1 as the offset value.

What is the corret syntax for using max function

Still using bloody OpenOffice Writer to customize my sale_order.rml report.
In my sale order I have 6 order lines with 6 different lead time to delivery. I need to show the maximum out of the six values.
After many attempt I have abandoned using the reduce function as it works erratically or not at all most of the time. I have never seen anything like this.
So I thought I'd give a try using max encapsulating a loop such as:
[[ max(repeatIn(so.order_line.delay,'d')) ]]
My maximum lead time being 20, I would expect to see 20 (yes well that would be too easy, wouldn't it!).
It returns
{'d': 20.0}
At least it contains the value I am after.
But; if I try and manipulate this result, it disappears altogether.
I have tried:
int(re.findall(r'[0-9]+', max(repeatIn(so.order_line.delay,'d')))[0])
which works great from the python window, but returns absolutely nothing in OpenERP.
I import the re from my sale_order.py file, which I have recompiled into sale_order.pyo:
import time
import re
from datetime import datetime, timedelta
from report import report_sxw
class order(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context=None):
super(order, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'datetime': datetime,
'timedelta': timedelta,
're': re,
})
I have of course restarted the server many times. My test install sits on windows.
So can anyone tell me what I am doing wrong, because I can make it work from Python but not from OpenOffice Writer!
Thanks for your help!
EDIT 1:
The format
{'d': 20.0}
is, according to python, a dictionary. Still in Python, to extract the integer from a dictionary it is possible to do it like so:
>>> dict={'d': 20.0}
>>> print(dict['d'])
20.0
But how can I transpose this to OpenERP writer???
I have manage to get the result I wanted by importing functools and declaring the reduce function within the parameters of the sale_order.py file.
I then simply used a combination of reduce and max function and it works exactly as expected.
The correct syntax is as follow:
repeatIn(objects,'o')
reduce(lambda x, y: max(x, y.delay), o.order_line, 0)
Nothing else is required.
Enjoy!

Is there any way in XQuery to get the current time in milliseconds since some Epoch?

XQuery offers various date/time functions like current-dateTime(), however I can't seem to find one which gives me the time in milliseconds since Epoch. Functions to extract hours, minutes and seconds seem to exist too individually.
What is the right way to get the Epoch time (i.e. unix time or similar) in XQuery?
(current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xs:dayTimeDuration('PT0.001S')
returns the number of seconds as a duration, and then divides by 1 millisecond to get the number of milliseconds as a number.
thank you for the tips. I modify the code for Oracle Service Bus 11g (OSB 11g) Xpath editor in case someone else needs it
{ (fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xdt:dayTimeDuration("PT0.001S") }
Additional tricks on Aditya's answer for OSB 11g.
There has an annoying bug on XQ Editors that will change div and operator into a , (comma).
Just put a conversion function in front of that code. such as xs:long, xs:string
ex.
{ xs:long((fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xdt:dayTimeDuration("PT0.001S")) }

Resources