// Licensed Materials - Property of IBM
//
// IBM Watson Analytics
//
// (C) Copyright IBM Corp. 2015
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
( function( Date, ObjectPolyfill )
{
"use strict";
/**
* Polyfills for {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date Date}.
* @class module:barejs/polyfill.Date
*/
/** @lends module:barejs/polyfill.Date */
var stat = {};
/** @lends module:barejs/polyfill.Date# */
var proto = {};
/*istanbul ignore else: We test with __ES__ set to 3*/
if ( __ES__ < 5 )
{
/**
* The Date.now() method returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.
* @returns {number} The number of milliseconds.
*/
stat.now = function now()
{
return new Date().getTime();
};
( function()
{
/**
* Ensure the number is _length characters wide.
* @param {number} _value The number to pad.
* @param {number} _length The length to pad to. Note: values > 4 are not supported
* @returns {string} The number, optionally padded with leading zeros
*/
function padZero( _value, _length )
{
var nr = String( _value );
if ( nr.length < _length )
nr = "0000".substr( 0, _length - nr.length ) + nr;
return nr;
}
/**
* The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which
* is always 24 characters long: YYYY-MM-DDTHH:mm:ss.sssZ. The timezone is always zero UTC
* offset, as denoted by the suffix "Z".
* @returns {string} The date formatted as (zero UTC) ISO 8601.
*/
proto.toISOString = function toISOString()
{
// jshint validthis:true
return padZero( this.getUTCFullYear(), 4 ) +
"-" + padZero( this.getUTCMonth() + 1, 2 ) +
"-" + padZero( this.getUTCDate(), 2 ) +
"T" + padZero( this.getUTCHours(), 2 ) +
":" + padZero( this.getUTCMinutes(), 2 ) +
":" + padZero( this.getUTCSeconds(), 2 ) +
"." + ( this.getUTCMilliseconds() / 1000 ).toFixed( 3 ).slice( 2, 5 ) +
"Z";
};
}() );
// End of ES5 polyfill scope
}
ObjectPolyfill.polyfill( Date, stat, proto, exports, "Date" );
// End of module
}( Date, require( "./Object" ) ) );