LLK/scratch-html5 — pull request #54 by prokls (2014-03-21 18:58:39+00:00)
Title: SensingPrims.primTimestamp and Daylight Savings Time

Hi,

I guess ``SensingPrims.primTimestamp`` contains an implementation error. It implements the [Days since 2000](http://wiki.scratch.mit.edu/wiki/Days_Since_2000_%28block%29) brick. The source code looks as follows:
```javascript
SensingPrims.prototype.primTimestamp = function(b) {
var now = new Date();
var epoch = new Date(2000, 0, 1);
var dst = now.getTimezoneOffset() - epoch.getTimezoneOffset();
var msSince = now.getTime() - epoch.getTime();
msSince += (now.getTimezoneOffset() - dst) * 60000;
return msSince / 86400000;
};
```

The variable ``dst`` refers to the daylight saving time and contains the daylight saving time difference between the dates ``now`` and ``epoch`` in *minutes*. The variables contains the difference between the current time and 2000 in *microseconds*. So far so good.

Now ``msSince`` is increased by ``now.getTimezoneOffset() - dst`` minutes. This is a bug in my opinion.

Let's consider the following situations:
* Currently Austria has UTC+01:00 (``now.getTimezoneOffset()`` is -60)
* Currently people in Utah have UTC-06:00
* On 30th of March 2014 Austria will switch to UTC+02:00
* On 16th of June 2014 Austria will have UTC+02:00 (``now.getTimezoneOffset()`` will be -120)
* On 16th of June 2014 Utah will have UTC-07:00

Thus on 16th of June 2014 (Austria) the dates differ by one additional hour between the dates. So the calculation must be something like ``now - epoch + 60`` (in minutes). ``dst`` (the variable above) at this point in time will be ``-60`` (``= -120 - (-60)``).

Thus the source code must look like:

```javascript
var msSince = now.getTime() - epoch.getTime();
msSince += (-dst) * 60000;
```

The testcase by @brianpilati now tells me an error "Expected 5280 to equal 5280.25". This is another issue (0.25 is an issue related to his timezone UTC-06:00). But 5280 is the correct number of days between the first day of 2000 at minute 0 and 16th of June 2014 00:00.

(Don't get confused that timezones are not an issue here. We are looking at the difference between two timestamps and the timezones neutralizes themselves in this difference.)

git blame tells me that @nathan originally wrote those lines of code.