I'm trying to create a function, in Coldfusion, that will create an event by the Week of the Month, rather than by the Day of the Month.
An example would be that the event should be scheduled every 2nd week of a month, rather than the 2nd Tuesday of a month.
However, I've come across the problem that months can have anywhere from 4 to 6 weeks, and if someone scheduled an event on the 5th or 6th week of the month, it wouldn't repeat in the months that don't have 5 or 6 weeks.
I'm at a bit of a loss as to how to approach the problem, so any brainstorming advice would be greatly appreciated.
You'll need to find the lowest common denominator and that is February. February has 28 days when not leap year. A week has 7 days and 4 x 7 = 28 so that means you can not provide a function that reliably allows for scheduling on week 5 (or 6, 7, 8, etc) of every month. One work around would be that if there is no logical day for the scheduled week that month then run the task on the final day of the month or the first day of the following. On the last day for example you can check for any tasks scheduled later in the month that can not be run and then run them.
Related
I would like to create a perpetual calendar in Power BI (Power Query) with the holidays. The thing is, I live in Canada and Easter and Victoria Day are quite complicated to integrate in this kind of calendar.
For the perpetual calendar, I used this technique (you can find the code on this website), which is very effective. It's "simply" a function to which you tell that you want a calendar from this date to this date and it generates everything you want and probably more. However, the calendar doesn't know which day is a holiday. So you need to have another request in Power BI with all the holidays for that period. Then you tell the calendar to use this holiday request as a reference point and then it will know which day is a holiday.
This is where it gets very complicated. Some holidays are based on a specific date, some are based on a specific day and others vary a lot.
Based on a specific date : New Year's Day, January 1st ; Saint-Jean-Baptiste Day, June 24 ; Canada Day, July 1st ; National Day for Thruth and Reconciliation, September 30 ; Remembrance Day, November 11 ; Christmas Day, December 25 ; Boxing Day, December 26.
Based on a specific day : Labour day, first Monday of September ; Thanksgiving, second Monday of October.
Those that vary a lot : Good Friday, Friday before Easter ; Easter, first Sunday after the Paschal full moon ; Easter Monday, Monday after Easter ; Victoria Day, last Monday preceding May 25.
Finally, some holidays happen only once to commemorate specific events like the death of the Queen on September 19, 2022.
I would like to create a function to which I indicate that I want all holiday for a specific period and it generates everything by itself. Then I could tell my calendar function to use it as a reference to know which day is a holiday. It would also be great if I could add some new holiday here and there for specific events like the death of the Queen.
For holidays like New Year's Day, Canada Day and Thanksgiving, I used this tutorial, but it's incomplete. Also, it doesn’t explain how to integrate holidays like Easter or Victoria Day. So this is where I'm stuck right now.
I know it's complicated but if someone can help me, it would be awesome.
As Jon suggest, I think it will be a lot easier to use the canada-holidays.ca/api.
I'm having issues with this API though. If I want multiple years in a single request, I need to create a request for each year and then append them. I'm trying to find a way to only have a single request but I'm struggling with this as well.
As soon as I find a solution, I'll update this post.
EDIT
Someone help me with that on another post. You can find the solution right here!
Run into a problem.
I need to have a yearly reset on an entitlement value but the reset point is a different date for each person. A person gets entitlement 6 months after their start date, so that +6months date is when they should have a reset. Here is the +6months column i made:
+6m = DATE(YEAR('Employee List'[Emp. Dates]),
MONTH('Employee List'[Emp. Dates])+6,
DAY('Employee List'[Emp. Dates]))
I ran into this problem when i saw that the excess was taking away a persons entitlement by the amount of days took throughout their entire time at the company. Here is the measure for Excess:
Excess Days = CALCULATE(SUM('Employee List'[Entitlement]) -
SUM('Leave combined'[Duration1]))
This is taking away all recorded days even from a few years ago.
Can i make a measure that pretty much says if we are past the +6months date (DD/MM(Year doesnt matter i just need the same time every year)), then it will take away their entitlement from that +6months date and will not pick up any days from before the +6months reset?
e.g. if the +6months is March 1 2015, currently it is taking all the days took from their start to today, i want it to reset at every year on March 1 so it would only take data from March 1 2019 - today and will reset once we past March 1 2020. If a person has took 25 days a year on average and they only have 20 days entitlement, it should show they 5 excess days but for me now it is taking the total days took away from their entitlement.
I understand this is hard to explain and you may not get it but i am happy enough to explain.
Dummy Sheet
It is easier to create a calculated column to do this. Perhaps something like:
Calc =
VAR Person = TableA[Person]
VAR Date1 = EDATE(Entitlement[Start Date],6)
RETURN IF(TableA[Start]<Date1,0,TableA[Duration])
This column will make the duration 0, wherever the start date is lesser than the +6m date from entitlement. Once this column is created you can simply sum up the field at whatever level required, to get the desired output. Hope this helps.
I work in an educational department where the start date of our academic calendar changes every year. Some years it might be week 9 of the year, some years it might be week 10. There is no formula used to figure out this start date, it's based a combination of factors and is picked by humans.
I want to be able to compare calls received in week 1 of the academic calendar 2017 to calls received in week 1 of the academic calendar 2018 and 2019.
I am using PowerBI desktop and trying to create a calendar table that includes a column "academic calendar week" or similar.
Does anyone have any suggestions on how to offset start date of the calendar by a different number of weeks for each year?
I have a time-series data set with 5 minute resolution for 4 years in SAS. In this data set,a particular several variables (e.g., SRAD) is measured for each 5 minutes at 9 different stations (e.g., ST1,..., ST9). It means for each 5 minute interval (for example, Feb. 1, 2015 1:00:00 PM) there are 9 samples for this variable. Here is are some of my variables:
Interval TAIR SRAD Date Time Month Day Year Hour Minute
Now, I am wondoering how I can create a new dataset including the data of Feb 1 to Feb 10, 2015 from 13-19 (time) with average of each variable from all stations. In other words, for each 5 min interval I need the average of all variables instead of 9 variables associated with the 9 stations (ST). Like this:
Interval TAIR_ave SRAD_ave Date Time Month Day Year Hour Minute
I need to do it in SAS. It'd be really appreciated if you can help.
Best Regards,
Paalang
I am currently trying to solve some problems from the USACO training website in preparation for an unrelated C++ programming competition.
However, I am stuck on this problem:
Does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given period of N years. The time period to test will be from January 1, 1900 to December 31, 1900+N-1 for a given number of years, N. N is non-negative and will not exceed 400.
The number N is provided in an input file and the output is to be a file with seven numbers in it, each representing the number of 13th's falling on a particular day of the week.
I was wondering how you guys would approach this problem. I am not looking for code or anything since that would just defeat the purpose of me doing this, instead just a starting point or an algorithm would be helpful.
So far the only thing I could think of is using the Doomsday Algorithm, however I am unsure about how I would implement that in code.
Any help would be greatly appreciated.
As Denny says, N is so small that you can easily iterate through the months using a table of days-in-a-month and a simple is-a-leap-year predicate to handle February. Just find out what day the 13th of Jan was in 1900 and then add up the elapsed days until 13th Feb, then 13th March etc.. Use a % operator to wrap the # of elapsed days back into a day-of-week value.
N is less than 400? well you just need to go over 365.25*400=146100 days at max. sounds easy to enumerate all of them, convert dates into year/month/date (with your favorite date conversion routine), testing for day of week is trivial.
I would precalculate the table though.
Just use brute force. Like this pseudocode example:
from datetime import date
day_names = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday']
counts = [0] * 7
for year in range(1900, 2300):
for month in range(1, 13):
counts[date(year, month, 13).weekday()] += 1
for day, count in zip(day_names, counts):
print('%s: %d' % (day, count))
The "hard" part is calculating the day of the week a date falls on. In C(++), you can use the mktime and localtime library functions if you know that your platform handles a large enough date range.