npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

moment-browser

v0.0.2

Published

An extenstion to moment.js that handles conversion from UTC -> Browser Time -> Custom Time Zone (and back again).

Downloads

15

Readme

Custom TimeZone Conversion for Single Page Apps Build Status

moment-browser.js is an extension to moment.js that helps convert Dates to/from the Browser Timezone to the TimeZone required by your browser based applications. E.g. You have a datepicker which the user expects to be in New York TZ, but you are using the application in the Pacific Timezones. When you display your server provided UTC Date Times they will show in the Browser TZ. This moment extension will create a new Date which helps offset the difference between the browser TZ and the TZ required by the application.

Usage

Works with browser environments.

<!-- Browser -->
<script type="text/javascript" src="/moment.js"></script>
<script type="text/javascript" src="/moment-browser.js"></script>
<script type="text/javascript">

// Create a date in New York Time
var newYorkDate = momentBrowser.tz("2017-02-02 12:00", "America/New_York");

// Grab converter object to faciliate Browser <-> Tz Conversion
var converter = newYorkDate.browserConverter();

// Display a date as New York DateTime in a Los_Angeles based browser 
var newYorkDateInBrowser = converter.asDisplayTz('America/New_York', 'America/Los_Angeles');

// The Application then changes the date time to 1pm.  User perception is that it is 1pm New York Time.
// Therefore we have to convert back inorder to persist correctly.
var onePmPST = momentBrowser.tz("2017-02-02 13:00", "America/Los_Angeles");
// Then we want to convert that back to the correct UTC time.
var newYorkDateOnePm = converter.fromDisplayTz(onePmPST)
console.log('newYorkDateOnePm = ' + newYorkDateOnePm.toDate());

</script>

Methods

moment().browserConverter()

Creates a converter helper object which handles conversion to and from the Browser TZ.

var newYorkDate = momentBrowser.tz("2017-02-02 12:00", "America/New_York");
var converter = newYorkDate.browserConverter();

converter.asDisplayTz(displayTimeZone, <browserTimeZone>);

Creates a new date object which is a datetime modified to replicate the display timezone. browserTimeZone is optional the code will try and guess it.

var newYorkDateInBrowser = converter.asDisplayTz('America/New_York');
var newYorkDateInBrowser = converter.asDisplayTz('America/New_York', 'America/Los_Angeles');

converter.fromDisplayTz(date);

Now a user makes a selection in the UI and changes the DateTime. On the workflow back to the server we need to convert this date back to it's correct current browser TimeZone value.

var onePmPST = momentBrowser.tz("2017-02-02 13:00", "America/Los_Angeles");
var newYorkDateOnePm = converter.fromDisplayTz(onePmPST)