Coder Social home page Coder Social logo

davidcalhoun / gps-time.js Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 192 KB

Small utility to convert times between GPS epoch (midnight January 6, 1980) and Unix epoch (midnight January 1, 1970), taking into account leap seconds.

License: MIT License

JavaScript 100.00%
gps time leap seconds epoch javascript

gps-time.js's Introduction

gps-time.js

Build Status Downloads

Small utility to convert times between GPS epoch (midnight January 6, 1980) and Unix epoch (midnight January 1, 1970), taking into account leap seconds.

It's not such a trivial matter as adding a constant number of leap seconds to all time inputs! For any two times, a different number of leap seconds may have elapsed between them. This utility helps figure out exactly how many have elapsed.

No dependencies! Very small: 464 bytes gzipped.

Works on the client and on the server (in Node.js).

Node.js installation

npm i --save gps-time

Usage

AMD and CommonJS are supported, with a fallback that defines this utility at window.gpsTime

In Node, you can bring in this utility with this:

var gpsTime = require('gps-time');

Converting from Unix time to GPS time.

var unixMS = Date.now();  // 1454168480000
gpsTime.toGPSMS(unixMS);  // 1138203697000

Converting from GPS time to Unix time.

var gpsMS = 1138203697000;
gpsTime.toUnixMS(gpsMS);  // 1454168480000

Tests

This comes with a small test suite which can be run like this:

$ npm install --dev
$ npm test

License

Licenced under MIT

gps-time.js's People

Contributors

davidcalhoun avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gps-time.js's Issues

Add typescript typings

Add the typings like described here

declare module 'gps-time' {
    export function toGPSMS(unixMS: number): number;

    export function toUnixMS(gpsMS: number): number;
}

to support typescript usage.

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.