Socket
Socket
Sign inDemoInstall

@lion/localize

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lion/localize - npm Package Compare versions

Comparing version 0.14.7 to 0.14.8

8

CHANGELOG.md
# Change Log
## 0.14.8
### Patch Changes
- 8ca71b8f: `parseDate('31.02.2020')` returned `'Mon Mar 02 2020 00:00:00 GMT+0100....'`. But not anymore, now it returns `undefined`.
- Updated dependencies [e2e4deec]
- @lion/core@0.13.3
## 0.14.7

@@ -4,0 +12,0 @@

12

package.json
{
"name": "@lion/localize",
"version": "0.14.7",
"version": "0.14.8",
"description": "The localization system helps to manage localization data split into locales and automate its loading",

@@ -26,7 +26,7 @@ "license": "MIT",

"scripts": {
"debug": "cd ../../ && yarn debug --group localize",
"debug:firefox": "cd ../../ && yarn debug:firefox --group localize",
"debug:webkit": "cd ../../ && yarn debug:webkit --group localize",
"debug": "cd ../../ && npm run debug -- --group localize",
"debug:firefox": "cd ../../ && npm run debug:firefox -- --group localize",
"debug:webkit": "cd ../../ && npm run debug:webkit -- --group localize",
"prepublishOnly": "../../scripts/npm-prepublish.js",
"test": "cd ../../ && yarn test:browser --group localize"
"test": "cd ../../ && npm run test:browser -- --group localize"
},

@@ -36,3 +36,3 @@ "sideEffects": false,

"@bundled-es-modules/message-format": "6.0.4",
"@lion/core": "0.13.2",
"@lion/core": "0.13.3",
"singleton-manager": "1.1.2"

@@ -39,0 +39,0 @@ },

@@ -59,6 +59,15 @@ import { localize } from '../localize.js';

const [year, month, day] = parsedString.split('/').map(Number);
if (year > 0 && month > 0 && day > 0) {
return new Date(Date.UTC(year, month - 1, day));
const parsedDate = new Date(Date.UTC(year, month - 1, day));
// Check if parsedDate is not `Invalid Date` or that the date has changed (e.g. the not existing 31.02.2020)
if (
year > 0 &&
month > 0 &&
day > 0 &&
parsedDate.getDate() === day &&
parsedDate.getMonth() === month - 1
) {
return parsedDate;
}
return undefined;
}
import { expect } from '@open-wc/testing';
import { parseDate } from '../../src/date/parseDate.js';
import { localizeTearDown } from '../../test-helpers.js';
import { localize } from '../../src/localize.js';
import { parseDate } from '../../src/date/parseDate.js';
/**

@@ -30,5 +30,7 @@ *

});
it('creates a date object', () => {
expect(parseDate('10/10/2000') instanceof Date).to.equal(true);
});
it('returns a date object', () => {

@@ -38,2 +40,3 @@ expect(equalsDate(parseDate('1-1-1979'), new Date('1979/01/01'))).to.equal(true);

});
it('handles all kind of delimiters', () => {

@@ -46,5 +49,22 @@ expect(equalsDate(parseDate('12-12-1976'), new Date('1976/12/12'))).to.equal(true);

});
it('handles different locales', () => {
localize.locale = 'en-GB';
expect(equalsDate(parseDate('31-12-1976'), new Date('1976/12/31'))).to.equal(true);
localize.locale = 'en-US';
expect(equalsDate(parseDate('12-31-1976'), new Date('1976/12/31'))).to.equal(true);
});
it('return undefined when no valid date provided', () => {
expect(parseDate('12.12.1976.,')).to.equal(undefined);
expect(parseDate('12.12.1976.,')).to.equal(undefined); // wrong delimiter
expect(parseDate('foo')).to.equal(undefined); // no date
localize.locale = 'en-GB';
expect(parseDate('31.02.2020')).to.equal(undefined); // non existing date
expect(parseDate('12.31.2020')).to.equal(undefined); // day & month switched places
localize.locale = 'en-US';
expect(parseDate('02.31.2020')).to.equal(undefined); // non existing date
expect(parseDate('31.12.2020')).to.equal(undefined); // day & month switched places
});
});
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