Code Monkey home page Code Monkey logo

timespace's Introduction

timespace Build Status

Compute fuzzy local time from a location. The default accuracy is zoom level 8. See "Regenerate timezones.json" section for instructions on how to change accuracy.

Timezone data is from https://github.com/evansiroky/timezone-boundary-builder/.

Install

npm install @mapbox/timespace

Test

npm run test

Use

Functions

var ts = require('@mapbox/timespace');

var timestamp = Date.now();
var point = [-122.27783203125, 37.84015683604136];
var time = ts.getFuzzyLocalTimeFromPoint(timestamp, point);
//=> (a `moment-timezone` object โ€“ see https://momentjs.com/timezone/)


var tile = [41, 98, 8];     // the tile [x, y, z] whose timezone we want to know
var timezone1 = ts.getFuzzyTimezoneFromTile(tile);
//=> 'America/Los_Angeles'


var quadkey = '02301021';   // the quadkey whose timezone we want to know
var timezone2 = ts.getFuzzyTimezoneFromQuadkey(quadkey);
//=> 'America/Los_Angeles'

./lib/timezones.json file contains the timezone name of every z8 tile that contains land.

If a tile/quadkey with zoom levels > 8 is passed into timespace functions, the timezone of its z8 parent is returned.

If a tile/quadkey with zoom levels < 8 is passed into timespace functions, the most popular timezone amongst its z8 children is returned.

Regenerate timezones.json

To update timezone.json,

  1. find the link address of the latest timezones.shapefile.zip release from https://github.com/evansiroky/timezone-boundary-builder/releases,
  2. replace the link address in this line with the the link from step 1
  3. run npm run regenerate
  4. run npm run test to verify the new timezones.json file is ok

To generate timezone.json for another zoom level:

  1. change the number in this line to the desired zoom level,
  2. run npm run regenerate
  3. run npm run test to verify the new timezones.json file is ok

timespace's People

Contributors

emgrasmeder avatar lily-chai avatar tcql avatar tmcw avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.