Socket
Socket
Sign inDemoInstall

globalize

Package Overview
Dependencies
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

globalize - npm Package Compare versions

Comparing version 1.3.0-alpha.3 to 1.3.0-alpha.4

doc/api/date/load-iana-time-zone.md

6

dist/globalize-runtime.js
/**
* Globalize Runtime v1.3.0-alpha.3
* Globalize Runtime v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize Runtime v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize Runtime v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize Runtime v1.3.0-alpha.3
* Globalize Runtime v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize Runtime v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize Runtime v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize Runtime v1.3.0-alpha.3
* Globalize Runtime v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize Runtime v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize Runtime v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -60,4 +60,161 @@ */

var ZonedDateTime = (function() {
function definePrivateProperty(object, property, value) {
Object.defineProperty(object, property, {
value: value
});
}
function getUntilsIndex(original, untils) {
var index = 0;
var originalTime = original.getTime();
// TODO Should we do binary search for improved performance?
while (index < untils.length - 1 && originalTime >= untils[index]) {
index++;
}
return index;
}
function setWrap(fn) {
var offset1 = this.getTimezoneOffset();
var ret = fn();
this.original.setTime(new Date(this.getTime()));
var offset2 = this.getTimezoneOffset();
this.original.setMinutes(this.original.getMinutes() + offset2 - offset1);
return ret;
}
var ZonedDateTime = function(date, timeZoneData) {
definePrivateProperty(this, "original", new Date(date.getTime()));
definePrivateProperty(this, "local", new Date(date.getTime()));
definePrivateProperty(this, "timeZoneData", timeZoneData);
definePrivateProperty(this, "setWrap", setWrap);
if (!(timeZoneData.untils && timeZoneData.offsets && timeZoneData.isdsts)) {
throw new Error("Invalid IANA data");
}
this.setTime(this.local.getTime() - this.getTimezoneOffset() * 60 * 1000);
};
ZonedDateTime.prototype.clone = function() {
return new ZonedDateTime(this.original, this.timeZoneData);
};
ZonedDateTime.prototype.getFullYear = function() {
return this.local.getUTCFullYear();
};
ZonedDateTime.prototype.getMonth = function() {
return this.local.getUTCMonth();
};
ZonedDateTime.prototype.getDate = function() {
return this.local.getUTCDate();
};
ZonedDateTime.prototype.getDay = function() {
return this.local.getUTCDay();
};
ZonedDateTime.prototype.getHours = function() {
return this.local.getUTCHours();
};
ZonedDateTime.prototype.getMinutes = function() {
return this.local.getUTCMinutes();
};
ZonedDateTime.prototype.getSeconds = function() {
return this.local.getUTCSeconds();
};
ZonedDateTime.prototype.getMilliseconds = function() {
return this.local.getUTCMilliseconds();
};
// Note: Define .valueOf = .getTime for arithmetic operations like date1 - date2.
ZonedDateTime.prototype.valueOf =
ZonedDateTime.prototype.getTime = function() {
return this.local.getTime() + this.getTimezoneOffset() * 60 * 1000;
};
ZonedDateTime.prototype.getTimezoneOffset = function() {
var index = getUntilsIndex(this.original, this.timeZoneData.untils);
return this.timeZoneData.offsets[index];
};
ZonedDateTime.prototype.setFullYear = function(year) {
var local = this.local;
return this.setWrap(function() {
return local.setUTCFullYear(year);
});
};
ZonedDateTime.prototype.setMonth = function(month) {
var local = this.local;
return this.setWrap(function() {
return local.setUTCMonth(month);
});
};
ZonedDateTime.prototype.setDate = function(date) {
var local = this.local;
return this.setWrap(function() {
return local.setUTCDate(date);
});
};
ZonedDateTime.prototype.setHours = function(hour) {
var local = this.local;
return this.setWrap(function() {
return local.setUTCHours(hour);
});
};
ZonedDateTime.prototype.setMinutes = function(minutes) {
var local = this.local;
return this.setWrap(function() {
return local.setUTCMinutes(minutes);
});
};
ZonedDateTime.prototype.setSeconds = function(seconds) {
var local = this.local;
// setWrap is needed here just because abs(seconds) could be >= a minute.
return this.setWrap(function() {
return local.setUTCSeconds(seconds);
});
};
ZonedDateTime.prototype.setMilliseconds = function(milliseconds) {
var local = this.local;
// setWrap is needed here just because abs(seconds) could be >= a minute.
return this.setWrap(function() {
return local.setUTCMilliseconds(milliseconds);
});
};
ZonedDateTime.prototype.setTime = function(time) {
return this.local.setTime(time);
};
ZonedDateTime.prototype.isDST = function() {
var index = getUntilsIndex(this.original, this.timeZoneData.untils);
return Boolean(this.timeZoneData.isdsts[index]);
};
ZonedDateTime.prototype.inspect = function() {
var index = getUntilsIndex(this.original, this.timeZoneData.untils);
var abbrs = this.timeZoneData.abbrs;
return this.local.toISOString().replace(/Z$/, "") + " " +
(abbrs && abbrs[index] + " " || (this.getTimezoneOffset() * -1) + " ") +
(this.isDST() ? "(daylight savings)" : "");
};
return ZonedDateTime;
}());
/**

@@ -106,3 +263,3 @@ * dayOfWeek( date, firstDay )

var dateStartOf = function( date, unit ) {
date = date.isGlobalizeDate ? date.clone() : new Date( date.getTime() );
date = date instanceof ZonedDateTime ? date.clone() : new Date( date.getTime() );
switch ( unit ) {

@@ -250,147 +407,4 @@ case "year":

var GlobalizeDate = (function() {
function getUntilsIndex( original, untils ) {
var index = 0,
originalTime = original.getTime();
// TODO Should we do binary search for improved performance?
while ( index < untils.length - 1 && originalTime >= untils[ index ] ) {
index++;
}
return index;
}
var GlobalizeDate = function( date, timeZoneData ) {
this.original = new Date( date.getTime() );
this.local = new Date( date.getTime() );
this.isGlobalizeDate = true;
this.timeZoneData = timeZoneData;
if ( !( timeZoneData.untils && timeZoneData.offsets && timeZoneData.isdsts ) ) {
throw new Error( "Invalid IANA data" );
}
this.setTime( this.local.getTime() - this.getTimezoneOffset() * 60 * 1000 );
};
GlobalizeDate.prototype.setWrap = function( fn ) {
var offset1 = this.getTimezoneOffset();
var ret = fn();
this.original = new Date( this.getTime() );
var offset2 = this.getTimezoneOffset();
this.original.setMinutes( this.original.getMinutes() + offset2 - offset1 );
return ret;
};
GlobalizeDate.prototype.clone = function() {
return new GlobalizeDate( this.original, this.timeZoneData );
};
GlobalizeDate.prototype.getFullYear = function() {
return this.local.getUTCFullYear();
};
GlobalizeDate.prototype.getMonth = function() {
return this.local.getUTCMonth();
};
GlobalizeDate.prototype.getDate = function() {
return this.local.getUTCDate();
};
GlobalizeDate.prototype.getDay = function() {
return this.local.getUTCDay();
};
GlobalizeDate.prototype.getHours = function() {
return this.local.getUTCHours();
};
GlobalizeDate.prototype.getMinutes = function() {
return this.local.getUTCMinutes();
};
GlobalizeDate.prototype.getSeconds = function() {
return this.local.getUTCSeconds();
};
GlobalizeDate.prototype.getMilliseconds = function() {
return this.local.getUTCMilliseconds();
};
GlobalizeDate.prototype.getTime = function() {
return this.local.getTime() + this.getTimezoneOffset() * 60 * 1000;
};
GlobalizeDate.prototype.getTimezoneOffset = function() {
var index = getUntilsIndex( this.original, this.timeZoneData.untils );
return this.timeZoneData.offsets[ index ];
};
GlobalizeDate.prototype.setFullYear = function( year ) {
var local = this.local;
return this.setWrap(function() {
return local.setUTCFullYear( year );
});
};
GlobalizeDate.prototype.setMonth = function( month ) {
var local = this.local;
return this.setWrap(function() {
return local.setUTCMonth( month );
});
};
GlobalizeDate.prototype.setDate = function( date ) {
var local = this.local;
return this.setWrap(function() {
return local.setUTCDate( date );
});
};
GlobalizeDate.prototype.setHours = function( hour ) {
var local = this.local;
return this.setWrap(function() {
return local.setUTCHours( hour );
});
};
GlobalizeDate.prototype.setMinutes = function( minutes ) {
var local = this.local;
return this.setWrap(function() {
return local.setUTCMinutes( minutes );
});
};
GlobalizeDate.prototype.setSeconds = function( seconds ) {
var local = this.local;
// setWrap is needed here just because abs(seconds) could be >= a minute.
return this.setWrap(function() {
return local.setUTCSeconds( seconds );
});
};
GlobalizeDate.prototype.setMilliseconds = function( milliseconds ) {
var local = this.local;
// setWrap is needed here just because abs(seconds) could be >= a minute.
return this.setWrap(function() {
return local.setUTCMilliseconds( milliseconds );
});
};
GlobalizeDate.prototype.setTime = function( time ) {
return this.local.setTime( time );
};
GlobalizeDate.prototype.isDST = function() {
var index = getUntilsIndex( this.original, this.timeZoneData.untils );
return Boolean( this.timeZoneData.isdsts[ index ] );
};
return GlobalizeDate;
}());
/**

@@ -414,3 +428,3 @@ * format( date, properties )

if ( properties.timeZoneData ) {
date = new GlobalizeDate( date, properties.timeZoneData() );
date = new ZonedDateTime( date, properties.timeZoneData() );
}

@@ -715,2 +729,13 @@

var dateFormatterFn = function( dateToPartsFormatter ) {
return function dateFormatter( value ) {
return dateToPartsFormatter( value ).map( function( part ) {
return part.value;
}).join( "" );
};
};
/**

@@ -811,3 +836,3 @@ * isLeapYear( year )

if ( properties.timeZoneData ) {
date = new GlobalizeDate( date, properties.timeZoneData() );
date = new ZonedDateTime( date, properties.timeZoneData() );
}

@@ -1004,8 +1029,12 @@

// Zone
case "z":
case "Z":
case "z":
case "O":
case "v":
case "V":
case "X":
case "x":
timezoneOffset = token.value;
if ( typeof token.value === "number" ) {
timezoneOffset = token.value;
}
break;

@@ -1065,4 +1094,6 @@ }

// Get date back from globalize date.
if ( date.isGlobalizeDate ) {
date = new Date( date.getTime() ); // FIXME can we improve this? E.g., toDate()
if ( date instanceof ZonedDateTime ) {
// TODO can we improve this? E.g., toDate()
date = new Date( date.getTime() );
}

@@ -1126,2 +1157,10 @@

function regexpSourceSomeTerm( terms ) {
return "(" + terms.filter(function( item ) {
return item;
}).reduce(function( memo, item ) {
return memo + "|" + item;
}) + ")";
}
valid = properties.pattern.match( datePatternRe ).every(function( current ) {

@@ -1244,3 +1283,3 @@ var chr, length, numeric, tokenRe,

token.type = current;
chr = current.charAt( 0 ),
chr = current.charAt( 0 );
length = current.length;

@@ -1267,2 +1306,34 @@

if ( chr === "z" ) {
var standardTzName = properties.standardTzName;
var daylightTzName = properties.daylightTzName;
if ( standardTzName || daylightTzName ) {
token.value = null;
tokenRe = new RegExp(
regexpSourceSomeTerm([ standardTzName, daylightTzName ])
);
}
}
// v...vvv: "{shortRegion}", eg. "PT".
// vvvv: "{regionName} {Time}" or "{regionName} {Time}",
// e.g., "Pacific Time"
// http://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
if ( chr === "v" ) {
if ( properties.genericTzName ) {
token.value = null;
tokenRe = new RegExp( properties.genericTzName );
// Fall back to "V" format.
} else {
chr = "V";
length = 4;
}
}
if ( chr === "V" && properties.timeZoneName ) {
token.value = length === 2 ? properties.timeZoneName : null;
tokenRe = new RegExp( properties.timeZoneName );
}
switch ( chr ) {

@@ -1444,3 +1515,13 @@

// Zone
case "v":
case "V":
case "z":
if ( tokenRe && new RegExp( "^" + tokenRe.source ).test( value ) ) {
break;
}
if ( current === "v" ) {
length = 1;
}
/* falls through */
case "O":

@@ -1503,2 +1584,3 @@

// Get lexeme and consume it.
// TODO: Improve performance by reducing the abusive use of regexps.
value = value.replace( new RegExp( "^" + tokenRe.source ), function( lexeme ) {

@@ -1559,6 +1641,7 @@ token.lexeme = lexeme;

Globalize._dateFormat = dateFormat;
Globalize._dateFormatterFn = dateFormatterFn;
Globalize._dateParser = dateParse;
Globalize._dateParserFn = dateParserFn;
Globalize._dateTokenizer = dateTokenizer;
Globalize._dateToPartsFormatterFn = dateToPartsFormatterFn;
Globalize._dateTokenizer = dateTokenizer;
Globalize._validateParameterTypeDate = validateParameterTypeDate;

@@ -1576,9 +1659,7 @@

Globalize.prototype.dateFormatter = function( options ) {
var formatterFn = this.dateToPartsFormatter( options );
return function() {
var parts = formatterFn.apply( this, arguments );
return parts.map( function( part ) {
return part.value;
}).join( "" );
};
options = options || {};
if ( !optionsHasStyle( options ) ) {
options.skeleton = "yMd";
}
return Globalize[ runtimeKey( "dateFormatter", this._locale, [ options ] ) ];
};

@@ -1585,0 +1666,0 @@

/**
* Globalize Runtime v1.3.0-alpha.3
* Globalize Runtime v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize Runtime v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize Runtime v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize Runtime v1.3.0-alpha.3
* Globalize Runtime v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize Runtime v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize Runtime v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize Runtime v1.3.0-alpha.3
* Globalize Runtime v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize Runtime v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize Runtime v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize Runtime v1.3.0-alpha.3
* Globalize Runtime v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize Runtime v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize Runtime v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize Runtime v1.3.0-alpha.3
* Globalize Runtime v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize Runtime v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize Runtime v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize v1.3.0-alpha.3
* Globalize v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -161,3 +161,3 @@ */

// If name of the function is not available, this is most likely due uglification,
// If name of the function is not available, this is most likely due to uglification,
// which most likely means we are in production, and runtimeBind here is not necessary.

@@ -164,0 +164,0 @@ if ( !fnName ) {

/*!
* Globalize v1.3.0-alpha.3
* Globalize v1.3.0-alpha.4
*

@@ -10,3 +10,3 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/

@@ -13,0 +13,0 @@ (function( root, factory ) {

/**
* Globalize v1.3.0-alpha.3
* Globalize v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize v1.3.0-alpha.3
* Globalize v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize v1.3.0-alpha.3
* Globalize v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize v1.3.0-alpha.3
* Globalize v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize v1.3.0-alpha.3
* Globalize v1.3.0-alpha.4
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/
/*!
* Globalize v1.3.0-alpha.3 2017-04-13T04:29Z Released under the MIT license
* Globalize v1.3.0-alpha.4 2017-05-18T13:55Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/*!
* Globalize v1.3.0-alpha.3
* Globalize v1.3.0-alpha.4
*

@@ -10,3 +10,3 @@ * http://github.com/jquery/globalize

*
* Date: 2017-04-13T04:29Z
* Date: 2017-05-18T13:55Z
*/

@@ -13,0 +13,0 @@

@@ -190,6 +190,6 @@ ## .dateFormatter( [options] ) ➜ function( value )

Using specific timeZones, i.e., using `options.timezone`. Note that prior to using
it, you must load IANA Timezone Data.
it, you must load IANA time zone data.
```js
Globalize.loadIANATimezone( require( "iana-tz-data" ) );
Globalize.loadTimeZone( require( "iana-tz-data" ) );
```

@@ -196,0 +196,0 @@

@@ -5,3 +5,4 @@ {

"cldr-data": "*",
"globalize": ">=1.3.0-a <2.0.0"
"globalize": ">=1.3.0-a <2.0.0",
"iana-tz-data": "*"
},

@@ -8,0 +9,0 @@ "devDependencies": {

@@ -12,2 +12,5 @@ /**

// IANA time zone data.
"iana-tz-data": "../bower_components/iana-tz-data/iana-tz-data",
// require.js plugin we'll use to fetch CLDR JSON content.

@@ -36,5 +39,7 @@ json: "./bower_components/requirejs-plugins/src/json",

"json!cldr-data/main/en/numbers.json",
"json!cldr-data/main/en/timeZoneNames.json",
"json!cldr-data/main/en/units.json",
"json!cldr-data/supplemental/currencyData.json",
"json!cldr-data/supplemental/likelySubtags.json",
"json!cldr-data/supplemental/metaZones.json",
"json!cldr-data/supplemental/plurals.json",

@@ -44,2 +49,3 @@ "json!cldr-data/supplemental/timeData.json",

"json!messages/en.json",
"json!iana-tz-data.json",

@@ -54,4 +60,5 @@ // Extend Globalize with Date and Number modules.

"globalize/unit"
], function( Globalize, enGregorian, enCurrencies, enDateFields, enNumbers, enUnits, currencyData,
likelySubtags, pluralsData, timeData, weekData, messages ) {
], function( Globalize, enGregorian, enCurrencies, enDateFields, enNumbers,
enTimeZoneNames, enUnits, currencyData, likelySubtags, metaZones,
pluralsData, timeData, weekData, messages, ianaTzData ) {

@@ -67,4 +74,6 @@ var en, like, number;

enNumbers,
enTimeZoneNames,
enUnits,
likelySubtags,
metaZones,
pluralsData,

@@ -75,2 +84,3 @@ timeData,

Globalize.loadMessages( messages );
Globalize.loadTimeZone( ianaTzData );

@@ -85,2 +95,8 @@ // Instantiate "en".

// Use Globalize to format dates on specific time zone.
document.getElementById( "zonedDate" ).textContent = en.formatDate( new Date(), {
datetime: "full",
timeZone: "America/Sao_Paulo"
});
// Use Globalize to format dates to parts.

@@ -87,0 +103,0 @@ document.getElementById( "dateToParts" ).innerHTML = en.formatDateToParts( new Date(), {

@@ -14,2 +14,8 @@ var Globalize = require( "globalize" );

var dateWithTimeZoneFormatter = Globalize.dateFormatter({
datetime: "full",
timeZone: "America/Sao_Paulo"
});
document.getElementById( "date-time-zone" ).textContent = dateWithTimeZoneFormatter( new Date() );
var _dateToPartsFormatter = Globalize.dateToPartsFormatter({ datetime: "medium" });

@@ -41,2 +47,3 @@ var dateToPartsFormatter = function( value ) {

document.getElementById( "date-label" ).textContent = Globalize.formatMessage( "date-label" );
document.getElementById( "date-time-zone-label" ).textContent = Globalize.formatMessage( "date-time-zone-label" );
document.getElementById( "date-to-parts-label" ).textContent = Globalize.formatMessage( "date-to-parts-label" );

@@ -65,2 +72,3 @@ document.getElementById( "relative-time-label" ).textContent = Globalize.formatMessage( "relative-time-label" );

document.getElementById( "date" ).textContent = dateFormatter( new Date() );
document.getElementById( "date-time-zone" ).textContent = dateWithTimeZoneFormatter( new Date() );
document.getElementById( "date-to-parts" ).innerHTML = dateToPartsFormatter( new Date() );

@@ -67,0 +75,0 @@ document.getElementById( "relative-time" ).textContent = relativeTimeFormatter( elapsedTime );

@@ -7,2 +7,3 @@ {

"date-label": "تاريخ",
"date-time-zone-label": "التاريخ (في منطقة زمنية محددة ل إيانا، على سبيل المثال، America/Sao_Paulo)",
"date-to-parts-label": "التاريخ (لاحظ الشهر القوي، تمت إضافة الترميز باستخدام formatDateToParts)",

@@ -9,0 +10,0 @@ "relative-time-label": "الوقت النسبي",

@@ -7,2 +7,3 @@ {

"date-label": "Datum",
"date-time-zone-label": "Datum (in einer bestimmten IANA-Zeitzone, z. B. America/Sao_Paulo)",
"date-to-parts-label": "Datum (beachten Sie den hervorgehobenen Monat, das Markup wurde mit dateToPartsFormatter hinzugefügt)",

@@ -9,0 +10,0 @@ "relative-time-label": "Relative Zeit",

@@ -7,2 +7,3 @@ {

"date-label": "Date",
"date-time-zone-label": "Date (in a specific IANA time zone, e.g., America/Sao_Paulo)",
"date-to-parts-label": "Date (note the highlighted month, the markup was added using formatDateToParts)",

@@ -9,0 +10,0 @@ "relative-time-label": "Relative Time",

@@ -7,2 +7,3 @@ {

"date-label": "Fecha",
"date-time-zone-label": "Fecha (en una zona horaria IANA específica, por ejemplo, America/Sao_Paulo)",
"date-to-parts-label": "Fecha (note el mes destacado en negro, el marcador de html se agregó utilizando dateToPartsFormatter)",

@@ -9,0 +10,0 @@ "relative-time-label": "Tiempo Relativo",

@@ -7,2 +7,3 @@ {

"date-label": "Data",
"date-time-zone-label": "Data (em um fuso horário IANA específico, por exemplo, America/Sao_Paulo)",
"date-to-parts-label": "Data (note o mês em negrito, a marcação HTML foi adicionada usando formatDateToParts)",

@@ -9,0 +10,0 @@ "relative-time-label": "Tempo relativo",

@@ -7,2 +7,3 @@ {

"date-label": "Дата",
"date-time-zone-label": "Дата (в определенном часовом поясе IANA, например, America/Sao_Paulo)",
"date-to-parts-label": "Дата (обратите внимание на сильный месяц, разметка была добавлена с помощью formatDateToParts)",

@@ -9,0 +10,0 @@ "relative-time-label": "Относительное время",

@@ -7,2 +7,3 @@ {

"date-label": "迄今",
"date-time-zone-label": "日期(在特定的IANA时区,例如America / Sao_Paulo)",
"date-to-parts-label": "日期(注意强烈的月份,使用formatDateToParts添加标记)",

@@ -9,0 +10,0 @@ "relative-time-label": "相对时间",

@@ -8,2 +8,3 @@ {

"html-webpack-plugin": "^1.1.0",
"iana-tz-data": "^2017.1.0",
"nopt": "^3.0.3",

@@ -10,0 +11,0 @@ "webpack": "^1.9.0",

@@ -11,2 +11,8 @@ var like, number;

// Use Globalize to format dates on specific time zone.
document.getElementById( "zonedDate" ).textContent = Globalize.formatDate( new Date(), {
datetime: "full",
timeZone: "America/Sao_Paulo"
});
// Use Globalize to format dates to parts.

@@ -13,0 +19,0 @@ document.getElementById( "dateToParts" ).innerHTML = Globalize.formatDateToParts( new Date(), {

@@ -17,2 +17,15 @@ {

"gregorian": {
"days": {
"format": {
"wide": {
"sun": "Sunday",
"mon": "Monday",
"tue": "Tuesday",
"wed": "Wednesday",
"thu": "Thursday",
"fri": "Friday",
"sat": "Saturday"
}
}
},
"months": {

@@ -33,3 +46,18 @@ "format": {

"12": "Dec"
},
"wide": {
"1": "January",
"2": "February",
"3": "March",
"4": "April",
"5": "May",
"6": "June",
"7": "July",
"8": "August",
"9": "September",
"10": "October",
"11": "November",
"12": "December"
}
}

@@ -49,8 +77,11 @@ },

"dateFormats": {
"full": "EEEE, MMMM d, y",
"medium": "MMM d, y"
},
"timeFormats": {
"full": "h:mm:ss a zzzz",
"medium": "h:mm:ss a"
},
"dateTimeFormats": {
"full": "{1} 'at' {0}",
"medium": "{1}, {0}"

@@ -73,2 +104,13 @@ }

}
},
"timeZoneNames": {
"metazone": {
"Brasilia": {
"long": {
"generic": "Brasilia Time",
"standard": "Brasilia Standard Time",
"daylight": "Brasilia Summer Time"
}
}
}
}

@@ -144,2 +186,17 @@ },

},
"metaZones": {
"metazoneInfo": {
"timezone": {
"America": {
"Sao_Paulo": [
{
"usesMetazone": {
"_mzone": "Brasilia"
}
}
]
}
}
}
},
"plurals-type-cardinal": {

@@ -146,0 +203,0 @@ "en": {

@@ -5,3 +5,3 @@ {

"scripts": {
"build": "globalize-compiler -l en -c cldr.json -m messages.json -o compiled-formatters.js app.js"
"build": "globalize-compiler -l en -c cldr.json -m messages.json -z iana-tz-data.json -o compiled-formatters.js app.js"
},

@@ -12,4 +12,5 @@ "devDependencies": {

"globalize-compiler": ">= 0.3.0-a <0.4.0",
"iana-tz-data": "^2017.1.0",
"jquery": "latest"
}
}

@@ -10,5 +10,7 @@ var like;

require( "cldr-data/main/en/numbers" ),
require( "cldr-data/main/en/timeZoneNames" ),
require( "cldr-data/main/en/units" ),
require( "cldr-data/supplemental/currencyData" ),
require( "cldr-data/supplemental/likelySubtags" ),
require( "cldr-data/supplemental/metaZones" ),
require( "cldr-data/supplemental/plurals" ),

@@ -20,2 +22,4 @@ require( "cldr-data/supplemental/timeData" ),

Globalize.loadTimeZone( require( "iana-tz-data" ) );
// Set "en" as our default locale.

@@ -27,2 +31,8 @@ Globalize.locale( "en" );

// Use Globalize to format dates in specific time zones.
console.log( Globalize.formatDate( new Date(), {
datetime: "full",
timeZone: "America/Sao_Paulo"
}));
// Use Globalize to format dates to parts.

@@ -29,0 +39,0 @@ console.log( Globalize.formatDateToParts( new Date(), { datetime: "medium" } ) );

@@ -6,4 +6,5 @@ {

"cldr-data": "latest",
"globalize": ">=1.3.0-a <2.0.0"
"globalize": ">=1.3.0-a <2.0.0",
"iana-tz-data": ">=2017.0.0"
}
}
{
"name": "globalize",
"version": "1.3.0-alpha.3",
"version": "1.3.0-alpha.4",
"description": "A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data.",

@@ -93,3 +93,4 @@ "keywords": [

"iana-tz-data": "0.0.4",
"matchdep": "0.3.0"
"matchdep": "0.3.0",
"zoned-date-time": "0.0.4"
},

@@ -96,0 +97,0 @@ "commitplease": {

@@ -149,3 +149,3 @@ # Globalize

| globalize/currency.js | 2.6KB | 0.6KB | [Currency module](#currency-module) provides currency formatting and parsing |
| globalize/date.js | 5.1KB | 3.8KB | [Date module](#date-module) provides date formatting and parsing |
| globalize/date.js | 7.7KB | 5.0KB | [Date module](#date-module) provides date formatting and parsing |
| globalize/message.js | 5.4KB | 0.7KB | [Message module](#message-module) provides ICU message format support |

@@ -173,3 +173,3 @@ | globalize/number.js | 3.8KB | 2.1KB | [Number module](#number-module) provides number formatting and parsing |

npm install globalize cldr-data
npm install globalize cldr-data iana-tz-data

@@ -180,2 +180,3 @@ ```js

Globalize.load( require( "cldr-data" ).entireMainFor( "en", "es" ) );
Globalize.loadTimeZone( require( "iana-tz-data" ) );

@@ -189,6 +190,14 @@ Globalize("en").formatDate(new Date());

Note `cldr-data` is an optional module, read [CLDR content](#2-cldr-content) section below for more information on how to get CLDR from different sources.
Note `cldr-data` is an optional module, read [CLDR content](#2-cldr-content)
section below for more information on how to get CLDR from different sources.
Read the [Locales section](#locales) for more information about supported locales. For AMD, bower and other usage examples, see [Examples section](#examples).
The [`iana-tz-data`](https://github.com/rxaviers/iana-tz-data) module is only
needed when IANA time zones (via `options.timeZone`) are used with date
functions. Read [IANA time zone data](#3-iana-time-zone-data) below for more
information.
Read the [Locales section](#locales) for more information about supported
locales. For AMD, bower and other usage examples, see [Examples
section](#examples).
### Installation

@@ -262,4 +271,22 @@

Learn [how to get and load CLDR content...](doc/cldr.md).
Learn [how to get and load CLDR content...](doc/cldr.md) and use
[`Globalize.load()`](#core-module) to load it.
#### 3. IANA time zone data
The IANA time zone (tz) database, sometimes called the Olson database, is the
standard data used by Unicode CLDR, ECMA-402, Linux, UNIX, Java, ICU, and
others. It's used by Globalize to circumvent the JavaScript limitations with
respect to manipulating date in time zones other than the user's environment.
In short, feed Globalize on IANA time zone data if you need to format or parse
dates in a specific time zone, independently of the user's environment, e.g.,
`America/Los_Angeles`.
It's important to note there's no official IANA time zone data in the JSON
format. Therefore, [`iana-tz-data`](https://github.com/rxaviers/iana-tz-data)
has been adopted for convenience.
Learn more on [`Globalize.loadTimeZone()`](#date-module).
### Usage

@@ -430,2 +457,9 @@

- **`Globalize.loadTimeZone( ianaTzData )`**
This method allows you to load IANA time zone data to enable
`options.timeZone` feature on date formatters and parsers.
[Read more...](doc/api/date/load-iana-time-zone.md)
- **`.dateFormatter( [options] )`**

@@ -451,2 +485,8 @@

// > "Nov 1, 2010, 5:55:00 PM"
.dateFormatter({ datetime: "full", timeZone: "America/New_York" })( new Date() );
// > "Monday, November 1, 2010 at 3:55:00 AM Eastern Daylight Time"
.dateFormatter({ datetime: "full", timeZone: "America/Los_Angeles" })( new Date() );
// > "Monday, November 1, 2010 at 12:55:00 AM Pacific Daylight Time"
```

@@ -453,0 +493,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc