json-dotnet-date
v0.1.7
Published
Converter for .net style json date strings like /Date(1445301615000-0330)/ to JS Date object with timezone support.
Downloads
3
Readme
Converter for .net style json date strings like /Date(1445301615000-0330)/ to JS Date object with timezone support.
Features
- Timezone parsing
- Shifting to local timezone
- Default timezone setup
- Compatible with npm|bower
Installation
npm install --save json-dotnet-date
or
bower install --save json-dotnet-date
<script type="text/javascript" src="json-dotnet-date.min.js"></script>
Options
useInputTimeZone {true|false}
Enables input timezone parsing.
var parse = require("json-dotnet-date")({
useInputTimeZone:true
}).parse;
// "2015-10-20T00:40:15.000-0330" => "2015-10-19T21:10:15.000Z"
var date = parse("/Date(1445301615000-0330)/")
// date equals to new Date(1445301615000)
defaultInputTimeZoneOffset {int} minutes
Offset for input date if useInputTimeZone not used
var parse = require("json-dotnet-date")({
defaultInputTimeZoneOffset:130
}).parse;
// "2015-10-20T00:40:15.000Z" => "2015-10-19T22:30:15.000Z"
var date = parse("/Date(1445301615000)/")
// date equals to new Date(1445293815000)
shiftToLocalTimeZone: {true|false}
Allows shift date to local timezone
// local timezone is UTC-0300
var parse = require("json-dotnet-date")({
shiftToLocalTimeZone:true
}).parse;
// "2015-10-20T00:40:15.000Z" => "2015-10-19T21:40:15.000Z"
var date = parse("/Date(1445301615000)/")
// date equals to new Date(1445290815000)
API
parse({string}):{Date}
Parses input string to JS Date object
testStr({string}):{bool}
Validates that input string have valid format
format({Date}):{string}
Format date to .net json date string
testObject({Object}):{bool}
Validates that input object is JS Date
options
Reference to options object
Build
Use console command
gulp
Test
Use console command
gulp test
or
mocha