I've developed a weird obsession with the first world war. I have a countdown clock to the 100th anniversary of the war. This clock is intended to countdown to 11:10 AM in Vienna on July 28th, 1914. This is when Austro-Hungary telegraphed its declaration of war to Serbia.I occasionally like to tweet or display events exactly 100 years after they originally occurred (e.g., Princip shoots Franz Ferdinand).

The problem I'm having is one of time zones. I noticed a difference of one hour between my live tweets and those of the BBC and thought perhaps the BBC might have goofed with the timezone somehow but was corrected by someone who said "Sarajevo now has DST but was on GMT+1 in 1914 - the same as BST today". I'm wondering if there is some way to verify this and also wondering if there is some orderly, programmatic way to convert dates/times I read in history books (like this excellent one) into an exact 100-years-later time in Los Angeles.

I'm using the PHP [man]DateTime[/man] functions, but I don't think these take into account any historical changes in the time-keeping policies of the various regions. For example, this script says that these functions think there's an hour time difference between London and Vienna in 1914:

		$tz = new DateTimeZone("Europe/Sarajevo");
		$dt = new DateTime("1914-07-28 11:10:00", $tz);
		echo $dt->getTimestamp() . "<br>";

	$tz2 = new DateTimeZone("Europe/London");
	$dt2 = new DateTime("1914-07-28 11:10:00", $tz2);
	echo $dt2->getTimestamp() . "<br>";

	echo "difference: " . ($dt->getTimestamp() - $dt2->getTimestamp()) . "<br>";

The result:

-1749217800
-1749214200
difference: -3600

The time difference is one hour then. The difference is also one hour now:

		$tz = new DateTimeZone("Europe/Sarajevo");
		$dt = new DateTime("2014-07-13 00:00:00", $tz);
		echo $dt->getTimestamp() . "<br>";

	$tz2 = new DateTimeZone("Europe/London");
	$dt2 = new DateTime("2014-07-13 00:00:00", $tz2);
	echo $dt2->getTimestamp() . "<br>";

	echo "difference: " . ($dt->getTimestamp() - $dt2->getTimestamp()) . "<br>";

result:

1405202400
1405206000
difference: -3600

This is getting confusing to me because I don't know if London observed DST then or whether Sarajevo was observing DST or not and how this might result in the same one-hour time difference we see today. If anyone can help me get a grip on this, I'd appreciate it.

Observations:
If neither Sarajevo nor London observed DST in 1914, and Sarajevo was GMT+1 then, the one-hour difference calculated for 1914 makes sense.
If London was observing DST in 1914 and Sarajevo was not, the times should be the same.

Curiously, the Wikipedia entry on DST says that DST was first used in WW1:

Starting on 30 April 1916, Germany and its World War I allies (Austria-Hungary) were the first to use DST (German: Sommerzeit) as a way to conserve coal during wartime. Britain, most of its allies, and many European neutrals soon followed suit. Russia and a few other countries waited until the next year and the United States adopted it in 1918.

A google translation of the German page on Sommerzeit says:

The determination was first introduced to "The May 1, 1916 will begin on April 30, 1916 in the afternoon 11 clock after the current era. The September 30, 1916 ending one hour after midnight the purposes of this Regulation ".

This suggests I could be headed for an exceedingly complex situation if I want to be accurate about this. Perhaps there is some test we can do to find a discontinuity in the PHP DateTime calculations (e.g., calculate some German timestamps on April 30, 1916 and look for discontinuities. Actually, let me try that:

		for($h=0; $h<24; $h++) {
			for($m=0; $m<60; $m++) {
				for($s=0; $s<60; $s++) {
					// calculate timestamp for $s and $s+1 and compare
					$tz = new DateTimeZone("Europe/Berlin");

				$datetime1 = "1916-04-30 " . str_pad($h, 2, "0", STR_PAD_LEFT) . ":" . str_pad($m, 2, "0", STR_PAD_LEFT) . ":" . str_pad($s, 2, "0", STR_PAD_LEFT);
				$dt1 = new DateTime($datetime1, $tz);
				$ts1 = $dt1->getTimestamp() . "<br>";

				$datetime2 = "1916-04-30 " . str_pad($h, 2, "0", STR_PAD_LEFT) . ":" . str_pad($m, 2, "0", STR_PAD_LEFT) . ":" . str_pad($s+1, 2, "0", STR_PAD_LEFT);
				$dt2 = new DateTime($datetime2, $tz);
				$ts2 = $dt2->getTimestamp();

				if (($ts2-$ts1) !== 1){
					echo "discontinuity found<br>";
					echo $dt1->format("Y-m-d H:i:s") . " : " . $dt1->getTimestamp() . "<br>"; 
					echo $dt2->format("Y-m-d H:i:s") . " : " . $dt2->getTimestamp() . "<br>";
					echo "The second time is " . ($dt2->getTimestamp() - $dt1->getTimestamp()) . " greater than the first<br>"; 
				}
			}
		}
	}

Wow! It looks like the PHP DateTime function does show a one-hour leap in 1916 in Berlin time:

1916-04-30 23:59:59 : -1693702801
1916-05-01 00:00:00 : -1693706400
The second time is -3599 greater than the first

I'm a little confused that this seems to be a leap back on the clock in springtime? These timestamps are negative (i.e., prior to 1970) and so the May 1 timestamp seems to be 'falling back' rather than 'leaping forward' as we usually do in spring??

    The timezone database PHP uses does include historical information.

    Thing is, you're going backwards - from hh:mm:ss to a timestamp (assuming, for example, that 22:59:59 will be followed by 23:00:00; possibly in the process passing through clock times that don't actually exist or are doubled up due to DST changes) - so any jump you see will be backwards.

    <?php
    
    
    $tz = new DateTimeZone('Europe/Berlin');
    
    $berlin = new DateTime('now', new DateTimeZone('Europe/Berlin'));
    $berlin->setTimestamp(-1693789201);
    $one_minute = new DateInterval('PT1M');
    for($ts = 0; $ts <= 100000; $ts += 60)
    {
    	echo $berlin->format('Y-m-d H:i  (\D\S\T:I)'), "\n";
    	$berlin->add($one_minute);
    }

    April 30, 1916 10:59pm was followed by midnight May 1 - when the clocks went forward at the start of daylight saving; there was no 11 pm April 30, 1916 in Berlin.

      Great news that PHP's time stuff has historical data -- and thanks for the link to the database.

      I had concocted a script to calculate the timestamp for every second in Sarajevo between 1900-01-01 00:00:00 and 1999-12-31 00:00:00 and compare it to the datetime constructed for the second following and report every discontinuity. This took quite awhile. As it turns out, Sarajevo has a pretty complicated timezone history. E.g., they appear to adopt daylight savings changes from April 1941 to September 1945, then they have no discontinuities until 1983. I'm guessing it had something to do with communism. At any rate, I definitely see that the DateTime constructors do seem to take into account historical changes.

      So I think I begin to understand the reason for the negative difference between these two times:

      1916-04-30 23:59:59 : -1693702801
      1916-05-01 00:00:00 : -1693706400
      The second time is -3599 greater than the first

      The basic idea is that there is no such time as 1916-04-30 23:59:59 in Berlin. However, the DateTime constructor, rather than throwing an error (which would probably cause a lot of teeth gnashing when programs break) it goes ahead and constructs a timestamp if such a time had existed in Berlin. Because we jumped straight from 22:59:59 to midnight on this day means that these two timestamps differ not by an hour but rather by one second...etc., etc. This script tells us 11pm and midnight have identical timestamps:

      $tz = new DateTimeZone("Europe/Berlin");
      	$dt1 = new DateTime("1916-04-30 23:00:00", $tz);
      	$ts1 = $dt1->getTimestamp();
      	$dt2 = new DateTime("1916-05-01 00:00:00", $tz);
      	$ts2 = $dt2->getTimestamp();
      
      echo "difference: " . ($ts2-$ts1) . PHP_EOL;
      

      the result:

      difference: 0

      Which is actually kind of mind blowing. It has also occurred to me that certain times can be ambiguous. If we are 'falling back' from 3am-2am on Halloween some year, then we can refer to 2:30 AM and be talking about two distinct moments an hour apart. :eek:

      So I decided to try and use these detailed DateTime database points to my advantage to try and resolve my primary questions (which still aren't definitively resolved, IMHO):
      1) Was that guy on twitter correct in saying that 10AM in Sarajevo on June 28, 1914 corresponds to 11AM in Sarajevo on June 28, 2014? I.e., is "100 years later" actually resulting in a one-hour change because Sarajevo would be observing DST now? I'm inclined to think so.
      2) What time in 2014 corresponds to exactly 100 years after 11:10AM July 28, 1914 in Vienna? Interestingly, two different approaches yield a result that differs by an hour for some reason:

      	// our time zone
      	$tz = new DateTimeZone("Europe/Vienna");
      
      $orig = new DateTime("1914-07-28 11:10:00", $tz);
      echo "original date: " . $orig->format("Y-m-d H:i:s T") . PHP_EOL; // yields 1914-07-28 11:10:00 CET
      echo "orig: " . $orig->getTimestamp() . PHP_EOL; // -1749217800
      
      
      $interval = DateInterval::createFromDateString('100 year');
      $cent_dt = $orig->add($interval); // this also modifies $orig
      echo "DateInterval: " . $cent_dt->format("Y-m-d H:i:s T") . PHP_EOL; // 2014-07-28 11:10:00 CEST
      
      
      // reset orig
      $orig = new DateTime("1914-07-28 11:10:00", $tz);
      
      
      $calc = strtotime($orig->format("Y-m-d H:i:s T") . " +100 years");
      $calc_dt = new DateTime("now", $tz);
      $calc_dt->setTimestamp($calc);
      echo "strtotime   : " . $calc_dt->format("Y-m-d H:i:s T") . PHP_EOL; // 2014-07-28 12:10:00 CEST
      

      The strtotime approach yields a datetime that is one hour later than the DateInterval approach. Which is correct? I'm inclined to think that the strtotime value is correct because Vienna would not be on CEST in 1914 (as daylight savings time did not exist then) whereas it is on CEST now. 11:10 AM in July 1914 would be a non-dst time and since Vienna is now on DST time, it would be an hour later which corresponds to 12:10.

        Write a Reply...