Echo JS 0.11.0

<~>

tracker1 comments

tracker1 1660 days ago. link 1 point
Looks like I can do what I need with tz-offset, which is only ~18k unpacked compared to close to moment/moment-timezone which are MASSIVE.

    var tzOffset = require("tz-offset")

    function todayAtTime(input /*17:00*/) {
      const now = new Date();
      const y = now.getFullYear();
      const m = `0${now.getMonth() + 1}`.substr(-2);
      const d = `0${now.getDate()}`.substr(-2);
      
      const ret = `${y}-${m}-${d}T${input}`;
      return ret;
    }

    function inDst(dtm) {
        const dstStart = new Date(dtm.getFullYear(), 2/*Mar*/, 14, 2);
        const dstEnd = new Date(dtm.getFullYear(), 10/*Nov*/, 7, 3);
        return (dtm < dstStart || dtm > dstEnd);
    }

    function parseAsTimezone(input, timezone, noDst) {
        const dtm = new Date(input);
        dtm.setMinutes(
            dtm.getMinutes() 
            + (-1 * dtm.getTimezoneOffset())
            + tzOffset.offsetOf(timezone)
        );
        
        const dstStart = new Date(dtm.getFullYear(), 2/*Mar*/, 14, 2);
        const dstEnd = new Date(dtm.getFullYear(), 10/*Nov*/, 7, 3)
        
        if (noDst) return dtm;
        
        switch (timezone) {
            case "America/Phoenix":
                // todo: other timezones without dst    
                break;
            default:
                if (inDst(dtm)) {
                    dtm.setHours(dtm.getHours() - 1);
                }
        }
        return dtm;
    }

    function todayAtTimezone(time, timezone) {
      return parseAsTimezone(todateAtTime(time), timezone);
    }

    // Phoenix same as Denver
    console.log(parseAsTimezone('2021-01-01T15:00:00','America/Los_Angeles').toJSON());
    console.log(parseAsTimezone('2021-01-01T15:00:00','America/Denver').toJSON());
    console.log(parseAsTimezone('2021-01-01T15:00:00','America/Phoenix').toJSON());


    // Phoenix same as LA
    console.log(parseAsTimezone('2021-05-01T15:00:00','America/Los_Angeles').toJSON());
    console.log(parseAsTimezone('2021-05-01T15:00:00','America/Denver').toJSON());
    console.log(parseAsTimezone('2021-05-01T15:00:00','America/Phoenix').toJSON());

    // Getting the Time set for a give IATA timezone TODAY
    console.log(todayAtTimezone('15:00', 'America/Los_Angeles').toJSON())
    console.log(todayAtTimezone('15:00', 'America/Denver').toJSON())
    console.log(todayAtTimezone(‘15:00', 'America/Phoenix').toJSON())
tracker1 1660 days ago. link 1 point
Seems like there could be some interesting uses.. but as it stands, the README doesn't match the interfaces, and playing with it on RunKit, I couldn't manage to get it working.

What I'd really like to do, would be to parse a given date as a TimeZone...

for examples:

    // local date, but not the right timezone
    var dtm = new Date('2021-02-21T15:00:00');

    // will now be local time on the host.
    var fixed = global.parseWithTimezone(
      '2021-02-21T15:00:00',
      'America/Phoenix'
    );

    // correct UTC value from date time as Phoenix time.
    fixed.toJSON(); // 2021-02-21T22:00:00.000Z


aside: This uses `moment` and `moment-timezone` which you should never use in the browser if you can avoid it.. these libraries are MASSIVE.
tracker1 1664 days ago. link 2 points
May actually switch to a tweaked version of this. Minor adjustment on font order, and adding a font family set for code/pre elements.
tracker1 1664 days ago. link 1 point
Definitely worth adding a Star and bookmarking... some of the references are a little dated, but well worth it.
tracker1 1667 days ago. link 1 point
Edited to recorded Twitch stream archive, since it's not accessible on the link posted.
tracker1 1669 days ago. link 1 point
If you're using a Proxy, it's best to use a function to create the proxy and handlers, in order to isolate/abstract any Map/Object used for stowing data outside the object being observed.
tracker1 1669 days ago. link 1 point
This is poor advice these days... most tooling is/has moved towards module patterns that isolate code based on modules.  Most browsers even have built in support for javascript modules at this point, and there are ever more sites that publish the likes of npm as ecmascript modules for easier use in that fashion.

Currently, these are a bit slower than what bundlers can do, but is definitely the way forward... this advice seems like a flashback to pre-2010 advice for JavaScript.  This really started to change in 2010-2012 with Browserify with 6to5 and later Webpack and Babel (renamed 6to5).  Now there's more options including Parcel, TypeScript, Babel, Webpack and others.
tracker1 1675 days ago. link 0 point
It's funny, I have a little bit of a reputation for being blunt and kind of an ass about things.  I'm anti-woke, anti-socialist, pro-libertarian etc, but man, this guy takes the cake.

Note: I did add the part in parens on the title, again I can be a bit of an ass.

It's really kind of funny, all things considered that someone perporting to be anti-spam has created more than every other source combined... and that's after adding, I think well over a hundred entries in the domain blocks and deleting dozens of accounts.

For the most part, most of the spam is actually posted by hand, and one-offs from new accounts, so even then the proposed methods wouldn't do too much, email validation would at least allow for blocking problem email domains, etc. But it's all cat and mouse.  At least people are commenting/discussing on here, about the only good thing to come of this.
tracker1 1675 days ago. link 7 points
Why attack it at all?  All you are doing is demonstrating you are a spoiled asshole.
[more]