Calculating start and end of UK summertime

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculating start and end of UK summertime
# 1  
Old 04-27-2011
Calculating start and end of UK summertime

I have a need to calculate when British Summer Time starts and ends. After messing around, the following seems to work in Bash.

echo `date +%Y`-03-`cal 3 \`date +%Y\` | grep -oE "^[[:digit:]]{2}" | tail 


echo `date +%Y`-03-`cal 10 \`date +%Y\` | grep -oE "^[[:digit:]]{2}" | tail 

Are there better ways? Would this method work for other countries?
# 2  
Old 04-27-2011
Britain gets summer?

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:
$ echo `date +%Y`-10-`cal 10 \`date +%Y\` | sed -n 's/^\([0-9]\{2\}\).*/\1/p' | tail -1`T01:00:00Z

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?
# 3  
Old 04-27-2011
Why not just use zdump and the appropriate timezone file? Look for isdst 1
zdump -v Europe/London | grep 2011

shows that BST started on March 27th and ends on Oct 30th.
This User Gave Thanks to fpmurphy For This Post:
# 4  
Old 04-27-2011
Some zdump can trim themselves:
zdump -v -c '2011,2011' Europe/London

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.

Last edited by jim mcnamara; 04-28-2011 at 11:32 AM.. Reason: finish code tags
# 5  
Old 04-27-2011
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:-

GMT & Britain, of course, being the world standard for time - and quite right too.

One way to get the date would be like this:-

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?

UK - as if you couldn't guess.
# 6  
Old 04-28-2011
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?
# 7  
Old 05-02-2011
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Splitting week start date and end date based on custom period start dates

Below are my custom period start and end dates based on a calender, these dates are placed in a file, for each period i need to split into three weeks for each period row, example is given below. Could you please help out to achieve solution through shell script.. File content: ... (2 Replies)
Discussion started by: nani2019
2 Replies

2. Shell Programming and Scripting

Retrieving sequences corresponding to start and end position

Hi all, I have a fasta file of a reference sequnce, I will like to retrieve sequences corresponding to a list of start and end position in another file >my_ref_seq GCCCTATAAGGGCAGAAGCTTGTCCTTCTTGTGCCAGTTATGACGTTTGTCCTAACTGCACATCTGGTAG... (4 Replies)
Discussion started by: Ibk
4 Replies

3. Shell Programming and Scripting

How can I search with start and end criteria?

Hello I'm using cygwin and wouldlike extract information from an xml file according specific values, but don't know how. Let's say in a file content looks like this: <tab> SURNAME=Mustermann NAME=Max CUSTOMER SINCE= 18.01.2000 ADDRESS=Birmingham ... (2 Replies)
Discussion started by: witchblade
2 Replies

4. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

5. Programming

Returning start/end indices

I have an array of distances and a len, for example len = 323 dist = I want to calculate the start and end index values around each distance in the array with a length of len from it. Values in dist are stored in ascending order. (4 Replies)
Discussion started by: kristinu
4 Replies

6. Shell Programming and Scripting

Perl regex using /START/../END/

I need help with perl code. I have a data file with lots of data example: data.txt file START DATA1 sjdfh kjhdf DATA2 sdkjfhk jds dshfgdf ... Around 20 - 30 lines END LDDDD awdkjasd a sdkahgdk jasdh SOME CRAP Some EMPTY lines etc START DATA1 sjdfh kjhdf DATA2 sdkjfhk jds... (2 Replies)
Discussion started by: chakrapani
2 Replies

7. Shell Programming and Scripting

searching between start and end time

Hello All, Below mentioned is my log file. I want to make a script which ask for start time and then end time and then search particular word between those lines. Like start time:2 end time: 4 and then search all values starting from cell 84 between this time. Please Help ... (2 Replies)
Discussion started by: wakhan
2 Replies

8. Shell Programming and Scripting

String as both start and end anchors in awk

Not sure if the title of this thread makes sense, but hopefully my explanation will. I'm using awk to print some stats from an apache accesslog. I would like to specify the regexp condition where only the two root pages of "index.html" and "/" are counted in my results. What I can't figure out... (3 Replies)
Discussion started by: picassolsus
3 Replies

9. UNIX for Advanced & Expert Users

Complete dump from start to the end

Hi all... I was accidentally wipe off my iphone and lost all the data in it:(. So I tried to use dd to create an image from iphone and ssh to the Mac by using: dd if=/dev/disk | ssh user@MacIP of='image.img' Then I mount this image on Mac/Windows and run recovery software because most of the... (1 Reply)
Discussion started by: seraphc
1 Replies

10. Shell Programming and Scripting

extract a particular start and end pattern from a line

hi In the foll example the whole text in a single line.... i want to extract text from IPTel to RTCPBase.h. want to use this acrooss the whole file Updated: IPTel\platform\core\include\RTCPBase.h \main\MWS2051_Sablime_Int\1... (7 Replies)
Discussion started by: manish205
7 Replies
Login or Register to Ask a Question

Featured Tech Videos