EJB Creating Calendar-Based Timer Expressions - timer

I need to create 3 timers.
First timer shall timeout every 3 days but roll over the next month. For example, If I want the timer to trigger every 3 days. So, the timer shall timeout on days of month 1, 4, 7, 10, 13, 16, 19, 22, 25 ,28. But if this month is 31 days then the timer shall trigger on days 31 then day 3 of the next month, if this month is 30 days it shall trigger on day 1 of the next month, but if this month is just 28 days then it shall trigger on day 3 of the next month.
Second timer shall every 3 weeks on Sunday.
Third timer shall trigger every 6 months on the end of the month.
I'm trying to use Calendar based timer (timerService.createCalendarTimer(schedule)) but I couldn't find a way to establish the above timers since the interval x/y is not applicable for months and weeks. And for days it doesn't support roll over next month. Any ideas?

Have you checked the use of ScheduledExpression? Some other examples here
If the standard API does not cover you needs then you might need to consider using a more specific library, for example Quartz
Hope that helps.

Related

iCal Recurring monthly event on the closest weekday possible? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I would like to create a recurring event on the 24th of every month and if the day falls on a weekend, schedule it for the closest weekday. If the day falls on a Saturday, I would like to schedule it for the previous weekday (Friday). If the day falls on a Sunday, I would like to schedule it for the next weekday (Monday). Is this something that is possible to do with iCal RRULE?
I have already seen a similar question, but that was for always the next weekday.
I was able to create a recurring event based on your requirements using this combined iCAL RRULE
RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=23,24;BYSETPOS=-1
RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=24,25;BYSETPOS=1
RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=23,24;BYSETPOS=-1
By setting BYSETPOS to -1, this rule will choose the last occurrence within the set occurrences that matched the rule.
If both 23 and 24 falls on weekdays, it will choose the last occurrence which is the 24th day
If 24 falls on a Saturday, only one occurrence will be matched based on the rule, Hence it will choose the 23rd day on Friday
If both 23 and 24 fall on weekends, no event will be created. This is why another rule is needed to resolve this issue.
RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYMONTHDAY=24,25;BYSETPOS=1
By setting BYSETPOS to 1, this rule will choose the first occurrence within the set occurrences that matched the rule.
If both 24 and 25 falls on weekdays, it will choose the first occurrence which is the 24th day
If 24 falls on a Sunday, only one occurrence will be matched based on the rule, Hence it will choose the 25th day on Monday
If both 24 and 25 fall on weekends, no event will be created based on this rule.

How to Schedule days and hours for every two minutes trigger in Azure Logic app?

Every two mins it should get a trigger for 3 hours.
Run the logic app every day at 9 am?
The above logic app triggers and runs for every 2 min.
how to set timing(3hrs) and for each day(every day) at 9 am?
eg: 10 Sep 2020 at 9 am to 12 should run, every 2 min trigger and finishs the task.
You should change Frequency From Minute to Day, then cilk Add new parameter to add At these hours and At these minutes.
Because At these minutes cannot use cron expressions, you can only follow the format of 0,2,4,6.....58 to make it execute every two minutes.
If you have any other questions, please let me know.

How to loop informatica sessions

I want to load one table for data for say 1 month starting from 1 April to 30 April in successive manner.
i.e after loading data for 1 April, date should automatically increment to 2, load the data and increment and so on, till its 30 April.
Also, data of 2 April depends on 1 April data. So i cannot give a date range to load randomly.
How can I do it?
It would be preferable to get the loads done in single session run, instead of running the session for several times.
Sort the source data by date and use a Transaction Control transformation to enforce a commit every time the date changes.

Implentation of a date in SQL Server

Disclaimer: I am just looking for a logic not code
John discovered a strange island called Rasa. The years and weeks on the island are weird. Digging deeper into the island's calendar, he found out that it is similar to rest-of-the-world's (ROW) calendar but the island calendar's Year starts on 1st week of February's calendar. John is asking you to help him solve the problem of converting ROW's calendar into Island's calendar. Here is the question.
You are given a date (today's date). You have to determine the Island week's number. The catch here is that the Island year starts from 1st week of February and every Island's week starts from Sunday and ends on a Saturday. Write a SQL statement in SQL Server to achieve this. Use SQL Server functions and devise a logic.
Input parameter: Any date.
Output parameter: Week No in Rasa Calendar.
Here is an example:
Date: 5th May 2015 --
Week No in ROW Calendar:19
Week No in Rasa's Calendar:14
Date: Jan 1 2017:
Week No in ROW Calendar:1
Week No in Rasa's Calendar:49
My question: can this be achieved in SQL Server?
My homework: I tried a couple of ways to solve the problem.
Approach #1:
Step 1: Calculate the total no of days between today and Feb 1.
Step 2: Divide it by 7 and add 1 to the result.
Later found out that this approach will not work if Feb 1 is on any day other than Sunday.
Eg: 1st Feb is on Wednesday. 5th Feb will be on Monday
So, 1st Feb is on Rasa's week 1, and 5th Feb is on Rasa's week no 2. According to my approach 1st and 5th feb are on week 1 which is incorrect.
Approach #2:
I thought removing 5 weeks of Jan from ROW's calendar should work
select
case
when f.RasaWeek = -4 then 48
when f.RasaWeek = -3 then 49
when f.RasaWeek = -2 then 50
when f.RasaWeek = -1 then 51
when f.RasaWeek = 0 then 52
else
f.RasaWeek
end as Rasa_week,
f.year, f.month, f.date
from
(select
datepart(wk, date) - 5 as RasaWeek, *
from
<datetable>
where
Year(date) in (2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018)) as f
Info: I tested this on a <datetable> but this code will break if there is a 53rd week. Notice that I was not able to take care of the 53rd week.
Any inputs to solve this problem are welcome.
With dates, it's almost always easier to make a calendar table and store the data you care about rather than trying to do anything beyond basic date arithmetic. Use SQL's strengths: storing and retrieving data.
In this case, what you care about are all of the first Sundays in February. If you store these dates in a table, the solution is:
RETURN
SELECT TOP 1
DATEDIFF(day,[date],#input_date) / 7
FROM IslandCalendarStartDates
WHERE [date] <= #input
ORDER BY [date] DESC
This way you don't need to worry about leap years or 53-weeks, or any of the edge cases. Just count the days from the most recent first Sunday in February and divide by 7. If you need to change the solution to accommodate a different start date, you only change the data, not the code.

Storing and searching opening/closing times for stores

I'm writing an application that indexes data for our stores, some of which are open late (8 am - 2 am). We need to be able to search this database quickly -- basically, to run a query to find which stores are open at a given point in time (now, Sunday at 1 am, whatever).
In addition, the open/close times can vary day-by-day -- some stores are closed on Sundays, for example.
The obvious solution to me would be to make a table where I have a row with the store ID, day, open time, and close time. For something like Monday, 8 am - 2 am, that would actually be two rows, one for Monday 0800 - 2400, and one for Tuesday 0000 - 0200.
We have a lot of stores, so the search has to perform well (basically, the data has to be index-friendly), but I'll also have to display this data back out in a human-readable format. With my current solution, that'd look something like this:
Monday: 8:00 - Midnight
Tuesday: Midnight - 2:00 am; 8:00 am - Midnight
I'm just wondering if anybody else has alternative solutions before I jump right to an implementation. Thanks!
When PBS (the US Public Broadcasting System) faced this same problem a couple of years ago, they invented the idea of the "30 hour day" -- Where 00:00 is midnight at the start of the day, 24:00 is midnight at the end of the day, 25:00 is 1am the next day, 30:00 is 6am the next day. That way Mon closing time of 26:00 is 2am Tues morning.
Rather than two records representing a single store's times for a day, it may be more object oriented to think of the "store day" as the object. That way 1 record = 1 store's times for a day. If you want to store the two sets of open/close times, just use four fields in the record instead of two--and adjust your queries appropriately.
Remember that your queries should use a library/api that you write and publish. The library will then deal with the data store and its data layout. No one but your library should be looking at the db directly.
Time zones are very important in this sort of app too. (Hopefully) at some point, the store chain will expand to cover more than one time zone. You'll then need to determine the local time of the query. -- May not the same as the time zone of your server which is handling the queries.
Further thoughts--
I now see that you're standardizing to GMT. Good. You could also use datetime values (vs time values) and standardize to a given week in time. Eg open time is Sun Jan 1, 1995 10am - Mon Jan 2, 1995 2am (using Jan 1, 1995 as a base since it was a Sunday).
Then rationalize your "current time and date" to match the same point in the week of Jan 1, 1995. Then query to find open store days.
HTH,
Larry

Resources