Giter Club home page Giter Club logo

moment-msdate's Introduction

moment-msdate Build Status npm version

A moment.js and moment-timezone.js plugin for parsing OLE Automation dates.

Visit http://markitondemand.github.io/moment-msdate/ for more information and examples.

About OLE Automation Dates

An OLE Automation date, or "MSDate" as we call it, is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25.

Read more about OLE Automation on MSDN (including DateTime.ToOADate and DateTime.FromOADate).

Note: OLE Automation dates are unspecified and they’re based on the local timezone by default. The moment library normalizes all time to UTC and as a result this library will return all values based on UTC time.

Usage

fromOADate(oaDate, [offset])

Convert an OA date to a moment:

moment.fromOADate(42298.6868055556) returns 2015-10-21T16:29:00.000Z

Convert an OA date with a known offset to UTC to a moment in UTC time

moment.fromOADate(42298.6868055556, 240) returns 2015-10-21T20:29:00.000Z
moment.fromOADate(42298.6868055556, 'America/New_York') returns `2015-10-21T20:29:00.000Z

toOADate()

Convert a moment to a floating point OA date in UTC:

const momentDate = moment('2015-10-21T16:29:00.000-07:00')
momentDate.toOADate() returns 42298.978472222225

Example Moment Formatting:

Convert OA date into Moment (OA Date is assumed to be in UTC)

const momentDate = moment.fromOADate(42298.6868055556);

If OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation in minutes

const momentDate = moment.fromOADate(42298.6868055556, 240)
momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC)
momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 8:29 PM' (UTC)

If OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation as a timezone

const momentDate = moment.fromOADate(42298.6868055556, 'America/New_York')
momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC)
momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 8:29 PM' (UTC)

Once the date is in UTC it can than easily be converted to any other timezone using moment-timezone.js

const momentDate = moment.fromOADate(42298.6868055556, 240)
momentDate.tz('America/New_York')
momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC)
momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 4:29 PM' (ET)

License

Copyright © 2014 Markit On Demand, Inc.

The "moment-msdate" Moment.js plugin is licensed under the Apache License, Version 2.0.

moment-msdate's People

Contributors

michael-lechner avatar brianbaker avatar dzmitrychuradze avatar mark-lewis-markit avatar jjustus avatar markhealey avatar zlatkovsky avatar camjjack 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.