I believe ksh93 has some date arithmetic tools. First Sunday after March/Oct 9 at 1 AM? Typo in October, too much March pasted in. I had a lesser grep, so I use sed:
You can use date as echo, or date once to variable or date once to make a command and eval it. You could call date iterating offsets until it met your template, to drop cal and the cal postprocessing.
Only if they adopt British Summer Time, and then you have to decide the effects of their time zone on date as well as time, and do they match the UK no matter what TZ?
Still, it begs the question of the need for some utility where you can ask for the dom of a Sunday in Mar 2011 with 9 < dom < 17. I suppose if you took cal apart a bit, it might not be too hard to make a calendar selector utility, maybe just a cal option / enhancement. You might tell it to start at 3/10/2011 and find 1 Sunday.
Well British Summer Time is defined as starting on the last Sunday of March and ending on the last Sunday of October. Our timezone setting is therefore explicitly set to:-
GMT0BST,M3.5.0,M10.5.0
GMT & Britain, of course, being the world standard for time - and quite right too.
One way to get the date would be like this:-
#!/bin/ksh
read YYYY?"Please enter the year required: "
cal 3 $YYYY|grep -v "^$"|tail -1|read BST_start rest
cal 10 $YYYY|grep -v "^$"|tail -1|read BST_end rest
echo "BST starts on $BST_start/3/$YYYY and ends on $BST_end/10/$YYYY"
Does that help?
Robin
Liverpool/Blackburn
UK - as if you couldn't guess.
Thanks for the replies. I guess the algorithm for summertime changeover varies by country. I didn't know about zdump, you have to browse the zoneinfo directory on your machine to find out what strings to use?
The definition for date to change and even the time of change varies with where you are in the world. I'd guess that each country just decided what was best for itself, although there is now a standardised date accross Europe. It caused no end of trouble when our mahines assumed that they were USA and just changed at an unexpected time.
Not much of the world uses Summer Time or Daylight Savings (same concept, different name in the USA) and I suppose that many as you get nearer the equator, is has less of an effect.
Well, it is a calendar function, so it varies amidst 7 pairs of dates. I am just saying that a remote place might want to stay N hours off London time, so they might change more in mid-day, and possibly the day before West of London.