How do I get Cron Expression over a specific range of dates? - java

I want to get valid dates between certain dates via cron expression. Is this possible?
Returns only 1 with getNextValidTimeAfter.
For example, my statement is as follows;
0 0 0? MAY, JUN, JUL MON, TUE 2020-2024
This means:
At 00:00:00 am, on every Monday and Tuesday, in May, June and July, between 2020 and 2024
What I want to do is;
To bring the days in this statement between June 2020 and September 2020.

Months are entered as numbers so it should be something like this: 0 0 0 ? 5-9 * 2020-2024. Look at this resource for more information.

Related

Create a cron that runs every friday with a specific interval

I want to create a cron that runs in this interval 16/01/2023 - 15/06/2023 every friday at 12 o'clock.
The cron that i created is "0 0 12 ? 1-6 FRI 2023" but i do not know how to put the days interval for january and june.
AFAIK you cannot. Probable 3 schedules:
0 0 12 16-31 1 FRI 2023
0 0 12 ? 2-5 FRI 2023
0 0 12 1-15 6 FRI 2023

cron expression for the last weekend of the month

i have a job to be run on the last weekend of the month (i.e) if the month has a sunday at the end it should run on sunday and if the month ends or has a saturday at the end the job should run on saturday.
I didnt find any documentation to build a cron expression for this case.
Thanks in advance.
You can use L in the day of week field
0 0 0 ? * SUNL
This will trigger at every last SUN of every month, e.g.
Sunday, August 31, 2014 12:00 AM
Sunday, September 28, 2014 12:00 AM
Sunday, October 26, 2014 12:00 AM
Sunday, November 30, 2014 12:00 AM
Sunday, December 28, 2014 12:00 AM
I don't see a way to specify the last weekend of a month since quartz does not allow to combine the L character with multiple days of week. So you can't do something like SATL,SUNL. If you want to trigger something on every last SAT and SUN I would define 2 cron expressions.
From the quartz documentation (Special characters)
L ("last") - .....
for example "6L" means "the last friday of the month".
I tested it with my cron expression view - a plugin that I wrote for eclipse
https://github.com/link-intersystems/eclipse-plugins-repository. Maybe it is also useful for you,

Cron Expression once each 2 days [duplicate]

This question already has answers here:
how to set cronjob for 2 days? [closed]
(3 answers)
Closed 9 years ago.
I need to create a cron expression that fires at a specific time every two days. So, for instance today is 26th of November. If I deploy my web app today and the scheduler should start the 28th the 30th the 2nd of december and so on...
Any help?
Thanks,
Luca
0 0 12 1/2 * ? *
Schedules
1. Wednesday, November 27, 2013 12:00 PM
2. Friday, November 29, 2013 12:00 PM
3. Sunday, December 1, 2013 12:00 PM
4. Tuesday, December 3, 2013 12:00 PM
5. Thursday, December 5, 2013 12:00 PM
For Ref: cronMaker
Quartz cookbook contains the How-To: Trigger That Executes Every 2 Days

wrong result in date difference in android

I want to perform a date operation in my android app. What I want is to subtract two dates and get the result. But subtraction leads to the wrong result whenever I change the time zone to central daylight time.
I use the following code to find the difference between the two dates.
Long lDateDiff = dtCycleDay.getTime() - m_dtHistory[0].getTime();
lDateDiff = lDateDiff / (1000 * 60 * 60 * 24);
Here in m_dtHistory[0], the date stored is Thu Mar 01 00:00:00 CST 2012.
And in my dtCycleDay variable the date changes from Thu Mar 01 00:00:00 CST 2012, Thu Mar 02 00:00:00 CST 2012, Thu Mar 03 00:00:00 CST 2012... and so on.
Now up to Thu Mar 11 00:00:00 CST 2012, the subtraction result is fine, but when the date changes to Thu Mar 12 00:00:00 CDT 2012, the CST changes to CDT and it show wrong subtraction result.
Why this happens and these happen only when I change the time zone to Central Daylight Time or pacific Daylight Time.
What do you mean by the "wrong" subtraction result?
My guess is that the result is 23 hours or 25 hours- which is exactly what I'd expect when a daylight transition occurs, as the intervening day is longer or shorter in terms of elapsed time. The "longer" day won't be relevant when dividing by 24, but the shorter one will... you're assuming that every day has 24 hours, and that you can therefore count the number of days by dividing the elapsed milliseconds by "the number of milliseconds in 24 hours". That doesn't work due to varying day lengths.
Don't forget that a Date value is purely an instant in time. It doesn't know about calendars or time zones... if you want to know the difference in "local" dates and times (where midnight to midnight is always 24 hours), I'd suggest using Joda Time instead... Date and Calendar don't really do that for you.
If the real problem you're describing is the time zone changing at the wrong date, that's a different matter entirely, and could be due to various different causes. For one thing, you should show exactly which time zone you're talking about: the abbreviations are ambiguous, whereas the tzdb names (e.g. "Europe/Paris") aren't.

GWT DateTimeFormat reverses timezone value

Consider the following code is run in GWT:
import com.google.gwt.i18n.client.DateTimeFormat;
...
DateTimeFormat fullDateTimeFormat = DateTimeFormat.getFullDateTimeFormat();
Log.info(fullDateTimeFormat.format(date, TimeZone.createTimeZone(-120)));
Log.info(fullDateTimeFormat.format(date, TimeZone.createTimeZone(0)));
Log.info(fullDateTimeFormat.format(date, TimeZone.createTimeZone(180)));
And supposing it is Greenwich time 16:00.
Why do I get the following output?
Monday, February 21, 2011 6:00:00 PM Etc/GMT-2
Monday, February 21, 2011 4:00:00 PM Etc/GMT
Monday, February 21, 2011 1:00:00 PM Etc/GMT+3
The expected one is
Monday, February 21, 2011 2:00:00 PM Etc/GMT-2
Monday, February 21, 2011 4:00:00 PM Etc/GMT
Monday, February 21, 2011 7:00:00 PM Etc/GMT+3
What is the right way to fix it?
"Etc/GMT-2" is actually (and very surprisingly) "+02:00", see http://en.wikipedia.org/wiki/Tz_database#Area:
In order to conform with the POSIX style, those zones beginning with "Etc/GMT" have their sign reversed from what most people expect. In this style, zones west of GMT have a positive sign and those east have a negative sign.
Your code leads to a different output on my machine (probably because of my different Locale):
Monday, 2011 February 21 18:00:00 UTC+2
Monday, 2011 February 21 16:00:00 UTC
Monday, 2011 February 21 13:00:00 UTC-3
So, it's not DateTimeFormat which is responsible for the reversing, but TimeZone.createTimeZone(int timeZoneOffsetInMinutes)!
Let's look a bit more into the GWT javadocs of com.google.gwt.i18n.client.TimeZone:
getOffset(Date date):
* Returns the RFC representation of the time zone name for the given date.
* To be consistent with JDK/Javascript API, west of Greenwich will be
* positive.
and composeGMTString(int offset):
* In GMT representation, +/- has reverse sign of time zone offset.
* when offset == 480, it should output GMT-08:00.
I had a look at the source code. It has comments saying
20:00 GMT0000, or 16:00 GMT-0400, or 12:00 GMT-0800
are all the same. As per that I infer the relation between time and timezone as the amount of time subtracted from GMT or added to the GMT. So 16.00 GMT becomes 1400 GMT -0200 or 1900 GMT +0300. Keeping that in mind we have to work the other way around to get the desired result.

Categories

Resources