Showing posts with label griping. Show all posts
Showing posts with label griping. Show all posts

Friday, March 25, 2022

JavaScript Date object is actually worse than I thought

So a few years ago I was complaining about some weird behavior I discovered in the JavaScript Date object. In particular, that new Javascript('2018-01-01') creates an object at GMT/UTC 0. Which is fine, except that the .getFullYear() method gets a value localized to my current time zone, which leads to unexpected results when my date is different than GMT-0.

I was just playing around with this again, and discovered that whether Date creates a localized object or not depends on the format of the value passed to the constructor:

new Date('2018-01-01')
Date Sun Dec 31 2017 17:00:00 GMT-0700 (Mountain Standard Time)
new Date('January 1, 2018')
Date Mon Jan 01 2018 00:00:00 GMT-0700 (Mountain Standard Time)

So yeah, kinda awful.

Thursday, February 22, 2018

The interface to JavaScript's Date object is kinda broken

Here's an amusing thing to type into your favorite JavaScript console:

new Date('2018-01-01').getFullYear()

The response I get is 2017, which is surprising, at best.

What's happening?

The first part of the problem is that the Date object is actually a date and time object, and so new Date('2018-01-01') creates an object that has the date and time of January 1st, 2018 00:00 GMT. Which in and of itself is a reasonable enough choice.

The part that leads to the surprising result is that .getFullYear() returns a localized result, and since I am in a GMT+7 time zone, January 1st, 2018 00:00 GMT is actually December 31st, 2017 17:00 local time, and so .getFullYear() tells me it's still 2017.

Of course, the Date interface is broken in other ways too (.getYear() is actually non-Y2K compliant, in spite of the fact that it was presumably first designed and implemented less than a decade prior to the year 2000).

Can anything be done?

It turns out that dealing with time and time zones is actually surprisingly complex, and given JavaScript's "colorful" history, it's not surprising that the Date interface has its share of quirks. Really, I just wish there as an object for dealing with dates alone, without an accompanying time. Date would be a fine name for that object, if it weren't already taken.

I'm in a situation where I want to be able to deal with dates in JavaScript, and it seems like my choices are either to use the Date object with its rather non-intuitive interface, or roll my own date-only object. Neither choice seems optimal, but I think rolling my own date-only object would add more inertia to my projects than I'm willing to take on right now.

Monday, May 22, 2017

Another Windows 7 BSOD

Not quite 6 weeks since last time. Not doing anything except browsing the web.

I'm mostly okay with Windows 7, but I sure wish it felt more stable than the old Windows 95/98 days.

Update: on further review, this is a hardware problem, no reason to blame Windows 7 (well, at least for my crashes).

Tuesday, May 2, 2017

Just a couple notes for web admins

I already have an app for your website, it's called Firefox. Also, if you can't be bothered to make your website work in a mobile browser, what is there to make me think it will be better in your app?

If I can't use your website with my ad blocker, I won't use your website. The reality is, there are very few websites in my world that I can't live without. Bank, work, library, that's pretty much it. If your site puts up one of those "please turn off your ad blocker to proceed" blocks, I'm just leaving and not coming back. I get that you guys need to make money, but the Internet is a hideous place without ad blocker, and I'm not giving it up.

Wednesday, April 12, 2017

Windows 7 just crashed on me

Total BSOD, sent to reboot land. Not the first time this has happened, either. I don't remember XP ever crashing on me like this.

This is not the 21st century I was promised.

Update: as noted above, this turns out to be a hardware problem.