Merge branch 'MDL-32509' of git://github.com/danpoltawski/moodle
[moodle.git] / lib / yui / 3.5.0 / build / datatype-date-parse / datatype-date-parse.js
blobe1cb178b4a85d92358e74049d083ee587693c6d6
1 /*
2 YUI 3.5.0 (build 5089)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('datatype-date-parse', function(Y) {
9 /**
10  * Parse number submodule.
11  *
12  * @module datatype
13  * @submodule datatype-date-parse
14  * @for DataType.Date
15  */
16 var LANG = Y.Lang;
18 Y.mix(Y.namespace("DataType.Date"), {
19     /**
20      * Converts data to type Date.
21      *
22      * @method parse
23      * @param data {String | Number} Data to convert. Values supported by the Date constructor are supported.
24      * @return {Date} A Date, or null.
25      */
26     parse: function(data) {
27         var date = null;
29         //Convert to date
30         if(!(LANG.isDate(data))) {
31             date = new Date(data);
32         }
33         else {
34             return date;
35         }
37         // Validate
38         if(LANG.isDate(date) && (date != "Invalid Date") && !isNaN(date)) { // Workaround for bug 2527965
39             return date;
40         }
41         else {
42             return null;
43         }
44     }
45 });
47 // Add Parsers shortcut
48 Y.namespace("Parsers").date = Y.DataType.Date.parse;
51 }, '3.5.0' );