 So many of my viewers probably already know this but if you don't I don't do computer stuff for a living I don't do programming or anything like that I'm actually a firefighter and Firefighters don't have a regular nine to five seven or five day a week schedule like a lot of people and There are different schedules out there for different departments But my department is probably one of the more common schedules where we work 24 on 48 off That means that I work for 24 hours and then I'll offer 48 for example if I work Monday Monday at 8 a.m. And I get off work at Tuesday at 8 a.m. And then I don't have to go to work until Thursday at 8 a.m. And it cycles through like that and there's good things and bad things to this schedule One of the great things is if I don't change shifts, which I've been on the job for 17 years now And I haven't changed a shift. I can predict Every day I'm going to work the rest of my career because you just count every third day on a calendar It's very simple you look whatever days. I work this week. I work the days before that next week So if I work Monday and Thursday this week next week I work Sunday and Wednesday and then and then Saturday and then the week after that I'd be working Tuesday and Friday So that's my schedule the question is the hard part is when you're off work working a weird schedule like this You don't have a weekend to look forward to so it's sometimes hard to remember what day it is And when I'm not at work I have to stop and think do I have to go to work tomorrow and I have to remember was I at work this morning at 8 a.m. If I remember waking up in my own bed at home, I have to go to work tomorrow But if I woke up at work, I don't have to go to work tomorrow But let's look at how we can predict out and write a short little shell script that tells us what shift We currently on again. There's three shifts a b and c so let's have a look at it So the first thing we need to do is we need to get a starting date for each shift as you can see I have a b and c here and I said to a date that I know was an a shift and I know was a b shift And I know it was a c shift as you can see by the year here I wrote this script many years ago, but we need to take those dates and we need to get it in Epoch or Unix timestamps so basically the number of seconds from January 1st 1970 to midnight at the beginning of these days So that's what this plus s does it gives us the seconds and also as you can see I put in a date for each one of these We got the first second and third But what I could have done is gotten the first date and then for the second and third date add one two days to it Just different options there. So once we have a date in seconds for each shift I have to get today's date and then we do a little bit of math and we can time figure out the time Elapsed between the two now right here. We're getting a variable or creating a variable of today And that's going to be today's date then we're going to take a b and c and do a little bit math and replace them So here we're taking today's date from there and we're going to subtract a Shift b shift and c-shift so we're getting today's date in seconds on each one of these lines Then we're subtracting these dates in seconds now if this is getting a little confusing for you Don't worry this script is in the link in the description this video It should be very simple to follow along in fact You might want to look at this while I'm explaining it as well But it's very basic math when you actually understand it So once we take today's date and subtract the previous date from it in seconds We should get a number and because today's date date is a For date a future date from this date. We should never get a negative number Then we're going to take that and we're going to divide it by 24 times 3600 3600 At times 24 that's going to give us the number of seconds in a day You could also just type in the number of seconds in a day But off the top of my head and know it was so we're doing 24 hours this number of seconds in an hour So we're going to take that and once we divide this by that We're going to divide it by three But this percent symbol here means divided by three and give us the remainder We're going to do all that for a b and c shift So again, this might sound complicated, but it's very basic again We're getting the difference in seconds between the two dates Then we're dividing it by the number of seconds in a day And then we're dividing that by three because we have three shifts and out of the three shifts Only one of them should be evenly divisible by three And if it is then we should get a remainder of zero because it's evenly divisible by three now We just check for a b and c Does a equals zero does b equals zero does c equals zero again only one of them should equal zero The double ampersand means the last statement was true. So it checks Is a zero if so the net go today is a shift If b equals zero zero, then it's going to say today is b shift And if c equals zero, then a let go today is c shift Again with me explaining it it might sound complicated But when you look at it it's basic math And it's only 10 lines of code and we're done and it probably could be shortened up a little bit in certain ways But I think it's very readable this way again. Check out the link in the description Let's go ahead and test this code out. So my script is called shift. It's made executable I dot slash it and when I run it I work tomorrow, which is a shift. So today should be c shift And there you go and this code again is very simple And could easily be ported to any language or just have this script run on a server that you can pull from And then you can display what shift it is in whatever interface you're looking to do it in And if you're a firefighter working a 24 on 48 off All you have to do is adjust the shift to match up your shifts because your a shift might be different than my shift But that's it. I hope you like this. I hope you enjoy the script Check out the link in the description of the video for the script up on pay spin And let me know what you think below. Is there anything you would do different? I'd love to see it Have a great day