GithubHelp home page GithubHelp logo

parseiso8601's Introduction

parseISO8601

Parse ISO 8601 subset that is a union of what is specified both in ECMAScript and ISO 8601.

Valid Formats

YYYY
YYYY-MM
YYYY-MM-DD
YYYY-MM-DDThh
YYYY-MM-DDThh:mm
YYYY-MM-DDThh:mm:ss
YYYY-MM-DDThh:mm:ss.m
YYYY-MM-DDThh:mm:ss.mm
YYYY-MM-DDThh:mm:ss.mmm

Parses local date formats.

Ecma parsing switches between local and UTC, parsing ISO 8601 extended format with missing z designator as UTC.

var date = new Date(Date.parse("2011-01-01"));
date.getFullYear() // 2010

But middle endian format works:

var date2 = new Date(Date.parse("01/01/2011"));
date2.getFullYear() // 2011

Native Date will parse dates that don't exist:

var date3 = new Date(Date.parse("11/31/2010"));
 date3.toString(); Wed Dec 01 2010

Likewise in YUI. Designed as documented. https://yuilibrary.com/yui/docs/datatype/datatype-dateparse.html.

EcmaScript 5 introduced incorrect ISO8601 parsing:

The value of an absent time zone offset is โ€œZโ€."

http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15 That's wrong. Missing z is to be interpreted as a local time.

ECMAScript draft 6 corrects this mistake:

| If the time zone offset is absent, the date-time is interpreted as a local time. https://people.mozilla.org/~jorendorff/es6-draft.html#sec-date-time-string-format

Historical problems with Date.parse: http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.4.2

The String may be interpreted as a local time, a UTC time, or a time in some other time zone"

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.