Comparing version 0.3.0 to 0.3.1
# Changelog | ||
## 0.3.1 | ||
* Fixed `toLocaleString` for fixed-offset zones in the absence of Intl | ||
* Added `Info.isValidIANAZone` | ||
* Made malformed zone specifiers result in invalid DateTime instances | ||
## 0.3.0 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "luxon", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Immutable date wrapper", | ||
@@ -5,0 +5,0 @@ "author": "Isaac Cambron", |
@@ -96,3 +96,3 @@ import { Util } from './util'; | ||
let z; | ||
if (dt.zone.universal) { | ||
if (dt.zone.universal && this.hasIntl) { | ||
// if we have a fixed-offset zone that isn't actually UTC, | ||
@@ -274,6 +274,5 @@ // (like UTC+8), we need to make do with just displaying | ||
const intl = { hour: 'numeric', hour12: true }; | ||
this.meridiemCache = [ | ||
DateTime.utc(2016, 11, 13, 9), | ||
DateTime.utc(2016, 11, 13, 19) | ||
].map(dt => this.extract(dt, intl, 'dayperiod')); | ||
this.meridiemCache = [DateTime.utc(2016, 11, 13, 9), DateTime.utc(2016, 11, 13, 19)].map( | ||
dt => this.extract(dt, intl, 'dayperiod') | ||
); | ||
} | ||
@@ -280,0 +279,0 @@ |
@@ -7,2 +7,3 @@ import { Duration } from '../duration'; | ||
import { FixedOffsetZone } from '../zones/fixedOffsetZone'; | ||
import { InvalidZone } from '../zones/invalidZone'; | ||
import { Settings } from '../settings'; | ||
@@ -196,4 +197,4 @@ import { InvalidArgumentError } from '../errors'; | ||
return FixedOffsetZone.instance(offset); | ||
} else if (IANAZone.isValidSpecier(lowered)) return new IANAZone(input); | ||
else return FixedOffsetZone.parseSpecifier(lowered) || Settings.defaultZone; | ||
} else if (IANAZone.isValidSpecifier(lowered)) return new IANAZone(input); | ||
else return FixedOffsetZone.parseSpecifier(lowered) || InvalidZone.instance; | ||
} else if (Util.isNumber(input)) { | ||
@@ -206,3 +207,3 @@ return FixedOffsetZone.instance(input); | ||
} else { | ||
return Settings.defaultZone; | ||
return InvalidZone.instance; | ||
} | ||
@@ -209,0 +210,0 @@ } |
@@ -5,2 +5,3 @@ import { DateTime } from './datetime'; | ||
import { Util } from './impl/util'; | ||
import { IANAZone } from './zones/IANAZone.js'; | ||
@@ -25,2 +26,11 @@ /** | ||
/** | ||
* Return whether the specified zone is a valid IANA specifier. | ||
* @param {string} zone - Zone to check | ||
* @return {boolean} | ||
*/ | ||
static isValidIANAZone(zone) { | ||
return !!IANAZone.isValidSpecifier(zone) && IANAZone.isValidZone(zone); | ||
} | ||
/** | ||
* Return an array of standalone month names. | ||
@@ -27,0 +37,0 @@ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat |
@@ -51,11 +51,2 @@ import { Util } from '../impl/util'; | ||
function isValid(zone) { | ||
try { | ||
new Intl.DateTimeFormat('en-US', { timeZone: zone }).format(); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
/** | ||
@@ -66,6 +57,15 @@ * @private | ||
export class IANAZone extends Zone { | ||
static isValidSpecier(s) { | ||
static isValidSpecifier(s) { | ||
return s && s.match(/^[a-z_+-]{1,256}\/[a-z_+-]{1,256}$/i); | ||
} | ||
static isValidZone(zone) { | ||
try { | ||
new Intl.DateTimeFormat('en-US', { timeZone: zone }).format(); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
// Etc/GMT+8 -> 480 | ||
@@ -85,3 +85,3 @@ static parseGMTOffset(specifier) { | ||
this.zoneName = name; | ||
this.valid = isValid(name); | ||
this.valid = IANAZone.isValidZone(name); | ||
} | ||
@@ -88,0 +88,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 too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1193709
31
16364