How to write pseudocode to print a message after every 2 years - pseudocode

I've been tasked to write pseudocode to assist in a staff notification program we want to implement. After every 2 years from the start date of employment, print the text "This is your renewal year". After the next two years, the code should run again and repeat like this until employment is terminated. So basically the code should run on year 2, then year 4 then year 6 etc until the employment ends. Please help

Related

Power Automate Recurrence Trigger : how to find last 5 working days of the month?

I need to create a recurrence in Power Automate so that it only runs in the last 5 working days of the month. I can't use a generic rule because months like February are different.
What I have done so far was using a similar recurrence that finds the last working day of the month but need help with optimising it for the last 5 working days instead.
The logic is that the flow runs every day and looks at the first day of the next month, then comes backwards to find the first working day and excludes Monday-Sunday. however, I need it to find the last 5 working days instead of 1.
Also the functions used are like this:
startOfMonth(addToTime(variables('Date'),1,'Month'))
addDays(variables('DateCountDown'),-1)
dayOfWeek(variables('DateCountDown'))
#and(not(equals(variables('DayOfWeek'), 0)), not(equals(variables('DayOfWeek'), 6)))
addDays(variables('DateCountDown'), -1)
dayOfWeek(variables('DateCountDown'))
disclaimer: I am not a pro user of power automate and found this flow in an old GitHub repository (written by Michael Ziemba) - thanks all for your help.
in response to teylin:
I get today (as before)
I get first day of next month (as before)
I go 7 days down now > addDays(variables('DateCountDown'),-7)
I initialize a variable to find week day > dayOfWeek(variables('DateCountDown'))
then varCounter variable as you said (varCounter > integer > 1)
then DO UNTIL loop until varCounter = 7
inside the loop I have 3 conditions: day of week <> 0 , dayof week <> 6 and formatDateTime(variables('DateCountDown'), 'dd-MM-yyyy') = formatDateTime(variables('Date'), 'dd-MM-yyyy') (to check today)
then trigger my stuff if yes,
increment varCounter by 1
Don't overthink this. Conceptually:
Get the first day of the next month (you already know how to do this)
get DayX by subtracting 7 from that date (you already do this with 1, now do it with 7)
By definition, 2 of the seven days between that DayX and the next month will be on a weekend. So, next, you start a loop that runs 7 times. Inside the loop, you have these actions:
add a condition with the following two checks
check if DayX is a weekday (you already know how to do this) AND
check if DayX is = today
In the Yes branch of the condition run the steps that you want to run on the last 5 weekdays, in the No branch do nothing
below the condition step, increment DayX by one day
loop
For the loop, first initialise a counter variable to the value 1. Add a Do Until action and set it to run until the counter is greater than 7. Inside the loop, do your calculations and your condition etc. As the last step of the loop, increment the counter variable by 1.

How to do a every 3 months cron job in laravel?

I am using laravel to schedule a job to run every 3 months at 2am, so I created:
$schedule->command('clean:market-history')->cron( '0 0 0,2 ? 1/3 * *');
But according to my research (by using: this reference) this indicates it will run every 3 months starting in January at 2 am. I got most of it right, I do want it to run every three months at 2 am, but if it starts in January does that not mean if I deploy in august, for example, that it wont start running till January?
Some resources stated to use: */3 how ever, the site, linked above, states the same, starting in January at 2 am.
Is this correct or am I missing something? Can some one explain?
If you want to run your command quarterly (First day of Jan, April, July, October) you can use Laravel's pre-canned quarterly function:
$schedule->command('YourCommandHere')->quarterly('02:00')->timezone('America/New_York');
If you want to run this command every three months starting from time of implementation (ie every 3 months starting now) you can use Laravel's cron function that lets you pass a custom cron line and that cron line would look like this:
$schedule->command('YourCommandHere')->cron('0 2 * */3 *')->timezone('America/New_York');
You can configure any iteration of laravel's cron function. Just use the crontab.guru reference I shared below. It's a lifesaver. Also, don't forgot to define timezone as I do if you intend on using a different timezone than what the server is set to.
To get all of the Laravel schedule features review this documentation: https://laravel.com/docs/8.x/scheduling
My most frequently used url to identify what my cron line should look like: https://crontab.guru

IceCube/Ruby A rule for every 1 month and 10 days

Is it possible to make a rule like every 1 month and 10 days? Obviously 40 days isn't correct since months have a variable number of days in them, and it isn't by day of month or a particular day of the week?
Something that would generate:
1/01/2014
2/10/2014
3/20/2014
4/30/2014
6/09/2014
I'm not so familiar with ice_cube, but just by checking out the README I think this could work:
schedule.add_recurrence_rule Rule.monthly.day_of_month(10)
Since IceCube's goal is to be iCal compliant, and that type of recurrence rule is not supported by the iCal spec as far as I can tell, this type of rule is impossible with IceCube.
Had to roll my own system.

VBS login script using between time ranges

I need to run a vbs script at login that will run a batch script based on a time range of between 22:00 and 06:00 the following day.
I have the current script as follows
If Hour(Now()) >= 20 AND hour(Now()) < 6 Then
//RUN SCRIPT
Else
//RUN OTHER SCRIPT
End If
Now the script runs fine when I use pre noon times e.g 6 and 11 but the about it does not. I can see the issue in that is is not factoring in the following days time and actually going back in time. What I need is the following
if time is 20:00 on day 1 but less than 06:00 on day 2 run the script else run the other script
This needs to run continuously between these times for every day of the week.
Please can you help?
Why not just change AND to OR? In that case when the hour of the day is greater than 20 then it will fire. if the hour of the day is less than 6 it will also fire. Look at it less of the time frame when it needs to fire and more of a time frame excluding those hours when it does not need to fire.
If Hour(Now()) >= 20 OR hour(Now()) < 6 Then
//RUN SCRIPT
Else
//RUN OTHER SCRIPT
End If
VB Script Date Functions

bash : Make job every x days

I have a bash script runned every day via cron.
In this bash I want to run some command but only every x day (x is fixed and will be 3, 4 or 5 I don't know at the moment)
I can test if the remainder of the division day of month / x equal 0
day_of_month % x = 0
I will work on a single month but not always between to month, for example months april - may with x = 3
1 2 3 4 5 6 7 8 9 ... 27 28 29 30 31 1 2 3 4 5 6 7 8 9 ... 27 28 29 30
x x x ... x x x x x ... x x
It not a big deal, but is there any other way to do this ?
PS : I don't want to explode my script and make 2 cron jobs (one every day : *, the other evevery x day : */x)
One easy solution would be to use "day of year" instead of day of month. Then there'd be no problem with different month lengths. You'd still get problems at the end of year, of course.
The "day of year" is available via date +%j.
If that is still not acceptable, you can use the seconds since 1970 (date +%s), and divide by days*24*60*60, then use the remainder of that. You'd still get problems with leap seconds, but otherwise it should be correct.
Using cron sounds the like the proper idea actually, because that is what cron is made for.
One idea though to solve your 'across months' problems: don't think in months, instead check whether the time-in-seconds-since-epoch % x*seconds-per-day is 0 ...
I would export a system variable with last date of execution and calculate the interval from it. It wouldn't work after a restart but I assume in this case the interval should be restored.
Have a look at the at command
Using that you can tell a script to call itself at a later date.
From manpage:
For example, to run a job at 4pm three
days from now, you would do at
4pm + 3 days, to run a job at 10:00am on July 31, you would do at
10am
Jul 31 and to run a job at 1am tomorrow, you would do at 1am
tomorrow.
If I had this problem, I would tell cron to run my script once every day, and inside the script I would calculate whether or not work needs to be done. That way, you have full control over it.
For example,
dayno=`date +%d`
let divided=daynum%3
if [ $divided == 0 ] ; then
exit 0
fi
# real work begins here
This script would work on any system that uses bash.
Does your job need to run every day? That is, does it do something on those days when your calculation does not result in a 0. If not, you could set up a job in cron thus:
0 12 3,6,9,12,15,18,21,24,27,30 * * <your job>
and it would run every third day (at 12 noon in my example).
I'm pretty sure that "Feb 30" would be safely ignored.

Resources