On Tuesday, October 20, 2020 at 10:56:13 AM UTC-7, Eric Shulman wrote:
>
> Set birth-date to "18831119"...
>
The LOCAL TIME result will be "November 18th 1883 16:00:00"
> but the UTC result will be "November 19th 1883 00:00:00"
>
> Set birth-date to "18831118"...
> The LOCAL TIME result will  "November 17th 1883 16:07:02"
> but the UTC result will be "November 17th 1883 23:59:02"
>
> There's some kind of weirdness happening with the time portion of the 
> formatting!
>

Well... I did a little research and, while I still don't have a solution, 
here's what I've found out:

1) Using the Chrome developer console:
* I entered $tw.utils.parseDate("18831119")
* The result was "Sun Nov 18 1883 16:00:00 GMT-0800 (Pacific Standard Time)"
* I entered $tw.utils.parseDate("18831118")
* The result was "Sat Nov 17 1883 16:07:02 GMT-0752 (Pacific Standard Time)"

So... it appears the source of the odd time value is $tw.utils.parseDate(), 
which is defined as:
$tw.utils.parseDate = function(value) {
 if(typeof value === "string") {
 return new Date(Date.UTC(parseInt(value.substr(0,4),10),
 parseInt(value.substr(4,2),10)-1,
 parseInt(value.substr(6,2),10),
 parseInt(value.substr(8,2)||"00",10),
 parseInt(value.substr(10,2)||"00",10),
 parseInt(value.substr(12,2)||"00",10),
 parseInt(value.substr(14,3)||"000",10)));
 } else if($tw.utils.isDate(value)) {
 return value;
 } else {
 return null;
 }
};

But that code just uses Date.UTC(...), which is JavaScript "native code", 
so its internal workings are not determined by TiddlyWiki at all.

2) So, I started to wonder, "Is there something special about November 18, 
1883?"... and this is what I found:

https://www.history.com/news/when-did-the-united-states-start-using-time-zones

Which says:

> On November 18, 1883, America’s railroads began using a standard time 
> system involving four time zones, Eastern, Central, Mountain and Pacific. 
> Within each zone, all clocks were synchronized. The railroad industry’s 
> plan was adopted by much of the country, although the time-zone system 
> didn’t become official across the United States until the passage of the 
> 1918 Standard Time Act


So, it appears that the strange time output is related to the original 
creation of standardized time zones!

The only work-around for this oddness is to use the trick that I suggested 
some time ago, which Tony referenced in his reply.

For accurate dates, regardless of local timezone, add "12" to the end of 
the date; e.g. "1883111812", which specifies a *time* of "12 noon".
Because timezones range from UTC-1200 to UTC+1200, the resulting computed 
date will be correct by avoiding the effect of the
localtime timezone offset that shifts the time back (or forward) by up to 
12 hours.

-e

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/e54a8847-6cb8-4deb-a7f6-4734d2ea23b9o%40googlegroups.com.

Reply via email to