Spring Batch Cron expression to meet below criteria - cron

Batch job should be triggered after every 10 minutes, from 7.30 am to 8.50pm,
Everyday in week except Sunday.

You could simply split it into two cron expressions.
First one:
- hour 7, minutes 30,40,50, MON-SAT
second one:
- hour 8, minutes 0,10,20,30,40,50, MON-SAT
With Spring it may look like this:
#Schedules({
#Scheduled(cron = "30,40,50 7 * * MON-SAT")
#Scheduled(cron = "*/10 8 * * MON-SAT")
})
public void doSomething() { //... }
The cron expressions itself may not be beautiful, for sure. However it should work as desired or at least point you into the right direction.

Related

How to get timezone RAW Offset? Node.JS

When you go to https://worldtimeapi.org/api/timezone/Europe/Berlin it says raw_offset=3600 , i'm trying to get this value in Node.JS. Need help please, i'm giving my code below but it's giving me wrong output
const moment = require("moment-timezone");
let timezone = "Europe/Warsaw";
let haha = moment().tz(timezone);
let timezone_raw = haha.utcOffset()
Doesn't look wrong they just use a different format.
Worldtime-API seems to use seconds where moment.js seems to use minutes.
According to my test moment.js also returns 60 from utcOffset().
You can either take the raw_offset and divide it by 60 (seconds per minute) to get 60 (minutes).
Or you can take the return from utcOffset() and multiply it by 60 to get 3600.

How to get the difference for the last event from two Windows?

We get the events from IoT hub as input, format is:
[
{
"events":[
{
"key":"Test1",
"value":1345.2270720045908
},
{
"key":"Test2",
"value":1882.9263119959833
}
],
"EventProcessedUtcTime":"2016-06-29T08:39:53.9293808Z",
"PartitionId":2,
"EventEnqueuedUtcTime":"2016-06-29T08:39:18.7320000Z",
},
{
"events":[
{
"key":"Test1",
"value":1456.6747534295491
},
{
"key":"Test2",
"value":1785.4095907491446
}
"EventProcessedUtcTime":"2016-06-29T08:49:53.9450060Z",
"PartitionId":2,
"EventEnqueuedUtcTime":"2016-06-29T08:49:19.0810000Z"
}
.........................
]
Every 10 mins, we got a batch of values from IoTHub. we want to get the “Test1” difference for each hour.
Like the Test1 last value in 3:00 – 4:00 is 600, the last value in 4:00 – 5:00 is 800, so the difference is 800 – 600 = 200, which is we want.
First, we want use the TumblingWindow with 1hour duration, get the Last Value from the current value, and get the Pervious Window Last value, then use the current last value – previous value, but we did not get the Previous Last Value succeed, so is anyway to get the LastValue in Previous Window?
Second, we want to use the HoppingWindow with Duration is 60Min, overlap is 10min with previous window, then we use the TopOne() with time stamp by * **asc and desc to get the First and Last value , then get the difference, but did not get we wanted, get more than two values during one hour.
And I found that we cannot use more WITH keyword in the query, so it is not convenient, we get the Value from the Events, we need use the CrossApply Get Elements(Input.Events) get all events, use “WITH” we use LAG(Value) function to get the previous value, but we cannot use the LAG(events.arrayvalue.value), it does not supported, so we want to use another query, also does not supported.
So is there any way we can use to get the last value in two window difference? So if you have a solution, thanks so much!
Firstly, the following statement is partially true:
And I found that we cannot use more WITH keyword in the query, so it
is not convenient, we get the Value from the Events, we need use the
CrossApply Get Elements(Input.Events) get all events, use “WITH” we
use LAG(Value) function to get the previous value, but we cannot use
the LAG(events.arrayvalue.value), it does not supported, so we want to
use another query, also does not supported.
Although you can only use a single WITH keyword, you can create multiple steps as follows:
WITH
FirstStep AS (SELECT * FROM Input),
SecondStep AS (SELECT * FROM FirstStep)
SELECT * INTO Output FROM SecondStep
First, we want use the TumblingWindow with 1hour duration, get the
Last Value from the current value, and get the Pervious Window Last
value, then use the current last value – previous value, but we did
not get the Previous Last Value succeed, so is anyway to get the
LastValue in Previous Window?
You'll first need to flatten the input so it can be used together with the LAG and LAST keywords. You are already doing this with the CrossApply.
I'm assuming you want the 'SUM' of the values here, but you can change the aggregate function when you need something else.
HourlyAggregate AS SELECT
key,
SUM(value) AS value
FROM CrossAppliedStep
GROUP BY key, TumblingWindow(hour, 1)
You should then be able to look back into the stream to get the previous value
LookBack AS SELECT
key,
LAST(value) OVER (PARTITION BY key LIMIT DURATION(hour, 1)) AS previous_value,
value AS current_value
FROM HourlyAggregate
Then calculating the delta is easy
SELECT
key,
value - previous_value AS delta
INTO Output
FROM LookBack
WHERE Key = 'Test1'
Second, we want to use the HoppingWindow with Duration is 60Min,
overlap is 10min with previous window, then we use the TopOne() with
time stamp by * **asc and desc to get the First and Last value , then
get the difference, but did not get we wanted, get more than two
values during one hour.
This is the correct output, HoppingWindow of 10 minutes, will output a record every 10 minutes, but with the data of the last 60 minutes.

Subtract days or years from new java.text.SimpleDateFormat

Application: SoapUI XML Resquest
I could swear this worked at one time where I use the below:
${=(new java.text.SimpleDateFormat("yyyy-MM-dd")).format( new Date() )}
To Subtract or Add I would add enclose the -# or +# like so:
${=${=(new java.text.SimpleDateFormat("yyyy-MM-dd")).format( new Date() )}-1
The result of the -1 is showing up as 1982
QUESTIONS:
Why is it taking away the -MM-dd part?
Why is it subtracting 23 years for -1
GOAL:
To be able to subtract from sysdate and the request show in yyyy-MM-dd format
i.e. if I want someone to be 65 years old - i want to subtract from sysdate to get that.
Again this is a SoapUI tag I'm populating the expression in.
You have the brackets misplaced! Let me break it down for you:
def yesterday = new Date() - 1
def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
def yesterdayFormatted = sdf.format(yesterday)
If you want it in a SoapUI property one liner:
${=new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date() - 1)}
Note that you can achieve the exact same thing with (slightly more compact):
${=String.format('%tF', new Date() - 1)}
Docs for the formatter.

How to calculate exact year, month and day between two dates in vc++/MFC

In my application i have to find out exact year, month and day between two dates. I tried with below snip. but answer is not correct. I used CTime for from to to dates. The result is obtained in CTimeSpan class. CTimeSpan has member function such as GetDays. We shall find out year, month and day from Total Days, but answer is not correct. Is any way to do ?
Thanks in advance
There is no common function to do that.
My idea would be:
COleDateTime date1(1979,12,31,0,0,0),
date2(2004,10,01,0,0,0);
// Get the normal differences
int iYears = date2.GetYear()-date1.GetYear(),
iMonths = date2.GetMonth()-date1.GetMonth(),
iDays = date2.GetDay()-date1.GetDay();
// Problematic underflow of days.
if (iDays<0)
{
// One month less
--iMonths;
// Advance from the start date until we reach the 1st of next month
for (iDays=0; (date1+COleDateTimeSpan(iDays,0,0,0)).GetDay()!=1; ++iDays)
;
// Now get the days from the 1st of the second date to the desired date.
iDays += static_cast<int>((COleDateTime(date2.GetYear(),date2.GetMonth(),1,0,0,0)-date2).GetTotalDays());
}
// underflow of months
if (iMonths<0)
{
--iYears;
iMonths +=12;
}
I don't see any CTimeSpan::GetTotalDays() function in the MSDN Docs.
Anyway, the GetTotalHours / GetTotalMinutes functions return the number of Complete Hours/Minutes and does not fully represent the TimeSpan value; the best way would be to use GetTotalSeconds and convert it as necessary.

Getting last day of current month

In Groovy, how can I find the last day of the current month?
Thanks for your sage advice and better wisdom.
Yeah, as you commented, Calendar.FIELD is probably your best friend (though groovy's TimeCategory also has neat tricks).
Here's how i made for the last day of the current month:
Calendar.with {
println instance.getActualMaximum( DATE )
}
I didn't understood what you meant by "break out the current weekday if I'm looping through a month". Perhaps getting the weekday for each month?
Calendar.with {
(JANUARY..DECEMBER).each { month ->
def cal = instance
cal[MONTH] = month
println cal[DAY_OF_WEEK]
}
}

Resources