markitondemand / moment-msdate Goto Github PK
View Code? Open in Web Editor NEWMoment.js plugin for parsing OLE Automation dates
Home Page: http://markitondemand.github.io/moment-msdate/
License: Apache License 2.0
Moment.js plugin for parsing OLE Automation dates
Home Page: http://markitondemand.github.io/moment-msdate/
License: Apache License 2.0
Using moment-msdate
in place of moment
or moment-timezone
in a TypeScript project requires type definitions for its methods. Moment + Timezone are already typed.
I'm still pretty new to TypeScript, but I may create a PR we can review and hopefully get this in.
All it may involve is (add anything I'm missing)
moment-msdate.d.ts
typings
keyI'm ok with the idea of a moment plugin for OADates, but I have a few concerns:
moment.fromOADate(x)
, not moment().fromOADate(x)
. By attaching it to the moment instance, you're first creating a "now" moment, then throwing it away.jsDate
and back into the moment constructor again.Offset(UTC(OADate)) + UTC(OADate)
. That's not necessarily going to yield the correct value. The offset applies at the destination - not at the source. Instead, you should be starting with a new Date of the OADate base and working from there.DateTime.FromOADate
which is as follows:// Creates a DateTime from an OLE Automation Date.
//
public static DateTime FromOADate(double d) {
return new DateTime(DoubleDateToTicks(d), DateTimeKind.Unspecified);
}
// Converts an OLE Date to a tick count.
// This function is duplicated in COMDateTime.cpp
internal static long DoubleDateToTicks(double value) {
if (value >= OADateMaxAsDouble || value <= OADateMinAsDouble)
throw new ArgumentException(Environment.GetResourceString("Arg_OleAutDateInvalid"));
long millis = (long)(value * MillisPerDay + (value >= 0? 0.5: -0.5));
// The interesting thing here is when you have a value like 12.5 it all positive 12 days and 12 hours from 01/01/1899
// However if you a value of -12.25 it is minus 12 days but still positive 6 hours, almost as though you meant -11.75 all negative
// This line below fixes up the millis in the negative case
if (millis < 0) {
millis -= (millis % MillisPerDay) * 2;
}
millis += DoubleDateOffset / TicksPerMillisecond;
if (millis < 0 || millis >= MaxMillis) throw new ArgumentException(Environment.GetResourceString("Arg_OleAutDateScale"));
return millis * TicksPerMillisecond;
}
While it's not going to be identical in JavaScript, your code should follow the same logic.
.toOADate()
This plugin should be installable via npm install moment-msdate
like all other plugins...
moment-msdate/moment-msdate.js
Line 12 in 1a020cd
Build seems to be failing because of es6 fat arrow.
Documentation should be updated to instruct users to run npm install --save moment-msdate
. Also, see about momentjs updating their documentation located here: http://momentjs.com/docs/#/plugins/msdate/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.