Craft By Zen

Writing

  • Luxon datetime library defaults startOf and endOf methods to UTC. But this isn’t great for end users who don’t live in UTC / GMT. To offset this, we need to grab the time zone offset from the user’s system.

    const systemTimeZoneOffsetInMinutes = new Date().getTimezoneOffset();  
    const systemTimeZoneOffsetInHours = systemTimeZoneOffset / 60;
    

    Then we can add the offset to the Luxon datetime object.

    const now = DateTime.now();
    const startOfLocalDay = now.startOf('day').plus({ hours: systemTimeZoneOffsetInHours });
    const endOfLocalDay = now.endOf('day').plus({ hours: systemTimeZoneOffsetInHours });
    
    Filed: 🚰 Stream
🔖 Tags