Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

Commit

Permalink
Datejs to moment migrate (#59)
Browse files Browse the repository at this point in the history
* Replaced datejs by moment
  • Loading branch information
Zenedith authored Jan 27, 2017
1 parent 69b64f3 commit dbfbd4b
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 75 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.2.0 / 2017-01-27
===================

* migrate to moment()

1.1.0 / 2017-01-27
===================

Expand Down
2 changes: 1 addition & 1 deletion lib/builder/event/productionEventBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const build = function build(event, productionYear) {
logger.debug('build production event:', event);

if (productionYear) {
productionYear = `${productionYear}-01-01`;
productionYear = `01.01.${productionYear}`;
}
else if (event && event.createdAt) {
productionYear = event.createdAt;
Expand Down
12 changes: 6 additions & 6 deletions lib/date.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require('datejs');
Date.i18n.setLanguage('en-US');
var moment = require('moment-timezone');
moment.tz.setDefault('Europe/Warsaw');

const parseIsoString = function parseIsoString(dateStr, formats = ["dd.MM.yyyy", "yyyy-MM-dd"]) {
const date = Date.parseExact(dateStr, formats);
const parseIsoString = function parseIsoString(dateStr, formats = ["DD.MM.YYYY"]) {
const date = moment(dateStr, formats);

if (date) {
return date.toISOString(dateStr);
if (date.isValid()) {
return date.toISOString();
}

return null;
Expand Down
4 changes: 2 additions & 2 deletions lib/resolver/vehicle/carProductionResolver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert-plus');
require('../../date');
const moment = require('moment');
const mapHelper = require('./../../mapHelper');

const PRODUCTION_YEAR_MAP_FIELD = 'production.year';
Expand All @@ -9,7 +9,7 @@ const resolve = function resolve(map/*, options*/) {

let productionYear = ~~mapHelper.getMapValue(map, PRODUCTION_YEAR_MAP_FIELD);

if (!productionYear || !Date.validateYear(productionYear)) {
if (!productionYear || !moment(productionYear, 'YYYY').isValid()) {
productionYear = null;
}

Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{
"name": "vehicle-history-model",
"version": "1.1.0",
"version": "1.2.0",
"description": "Vehicle history model.",
"main": "./index.js",
"dependencies": {
"assert-plus": "1.0.0",
"async": "2.1.4",
"datejs": "1.0.0-rc3",
"moment": "^2.17.1",
"moment-timezone": "^0.5.11",
"winston": "2.3.1",
"winston-loggly": "1.3.1"
},
"devDependencies": {
"chai": "3.5.0",
"config": "1.24.0",
"istanbul": "0.4.5",
"mocha": "3.2.0"
"mocha": "3.2.0",
"nsp": "2.6.2"
},
"scripts": {
"prepublish": "npm prune",
"prepublish": "npm prune && node_modules/nsp/bin/nsp check",
"test": "mocha --recursive test",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --recursive test",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --recursive test"
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --check-leaks --report lcovonly -- --recursive test"
},
"repository": {
"type": "git",
Expand All @@ -42,9 +44,9 @@
"license": "MIT",
"homepage": "https://github.com/vehicle-history/npm-vehicle-history-model",
"engines": {
"node": ">=4.0.0"
"node": ">=6.0.0"
},
"readmeFilename": "README.md",
"_id": "vehicle-history-model@1.1.0",
"_from": "vehicle-history-model@^1.1.0"
"_id": "vehicle-history-model@1.2.0",
"_from": "vehicle-history-model@^1.2.0"
}
43 changes: 21 additions & 22 deletions test/builder/eventsResponseBuilderTest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const options = require('config');
const eventsResponseBuilder = require('../../lib/builder/eventsResponseBuilder');
const chai = require('chai');
const should = chai.should();
Expand All @@ -20,7 +19,7 @@ describe('events response builder test', () => {
country: 'PL'
},
note: null,
createdAt: '2012-05-12T22:00:00.000Z',
createdAt: '12.05.2012',
expireAt: null,
description: 'First owner',
firstOwner: null,
Expand All @@ -31,7 +30,7 @@ describe('events response builder test', () => {
ownerType: null,
location: null,
note: null,
createdAt: '2012-05-16T22:00:00.000Z',
createdAt: '16.05.2012',
expireAt: null,
description: 'Abroad registration',
firstOwner: null,
Expand All @@ -42,7 +41,7 @@ describe('events response builder test', () => {
ownerType: null,
location: null,
note: null,
createdAt: '2012-06-16T22:00:00.000Z',
createdAt: '16.06.2012',
expireAt: null,
description: 'First registration',
firstOwner: null,
Expand All @@ -53,8 +52,8 @@ describe('events response builder test', () => {
ownerType: null,
location: null,
note: null,
createdAt: '2013-06-16T22:00:00.000Z',
expireAt: '2014-06-16T22:00:00.000Z',
createdAt: '16.06.2013',
expireAt: '16.06.2014',
description: 'Inspection (17.06.2014)',
firstOwner: null,
mileage: {
Expand All @@ -67,7 +66,7 @@ describe('events response builder test', () => {
ownerType: null,
location: null,
note: null,
createdAt: '2013-06-16T22:00:00.000Z',
createdAt: '16.06.2013',
expireAt: null,
description: 'Holder',
firstOwner: null,
Expand All @@ -78,7 +77,7 @@ describe('events response builder test', () => {
ownerType: null,
location: null,
note: 'note',
createdAt: '2014-06-16T22:00:00.000Z',
createdAt: '16.06.2014',
expireAt: null,
description: 'Deregistration',
firstOwner: null,
Expand All @@ -89,7 +88,7 @@ describe('events response builder test', () => {
ownerType: 'PRIVATE',
location: null,
note: null,
createdAt: '2014-06-16T22:00:00.000Z',
createdAt: '16.06.2014',
expireAt: null,
description: 'co owner',
firstOwner: null,
Expand All @@ -103,7 +102,7 @@ describe('events response builder test', () => {
country: 'PL'
},
note: null,
createdAt: '2012-05-12T22:00:00.000Z',
createdAt: '12.05.2012',
expireAt: null,
description: 'Changed registration location',
firstOwner: null,
Expand All @@ -114,7 +113,7 @@ describe('events response builder test', () => {
ownerType: null,
location: null,
note: null,
createdAt: '2012-05-12T22:00:00.000Z',
createdAt: '12.05.2012',
expireAt: null,
description: 'Stolen',
firstOwner: null,
Expand All @@ -129,7 +128,7 @@ describe('events response builder test', () => {
expect(events).to.have.length(10);

expect(events).to.have.deep.property('[0].type', 'PRODUCTION');
// expect(events).to.have.deep.property('[0].createdAt', '2012-06-13T00:00:00.000Z');
expect(events).to.have.deep.property('[0].createdAt', '1987-12-31T23:00:00.000Z');
expect(events).to.have.deep.property('[0].note', null);
expect(events).to.have.deep.property('[0].firstOwner', null);
expect(events).to.have.deep.property('[0].ownerType', null);
Expand All @@ -139,7 +138,7 @@ describe('events response builder test', () => {
expect(events).to.have.deep.property('[0].mileage', null);

expect(events).to.have.deep.property('[1].type', 'CHANGE_OWNER');
// expect(events).to.have.deep.property('[1].createdAt', '2012-06-13T00:00:00.000Z');
expect(events).to.have.deep.property('[1].createdAt', '12.05.2012');
expect(events).to.have.deep.property('[1].note', null);
expect(events).to.have.deep.property('[1].firstOwner', null);
expect(events).to.have.deep.property('[1].ownerType', 'PRIVATE');
Expand All @@ -150,7 +149,7 @@ describe('events response builder test', () => {
expect(events).to.have.deep.property('[1].mileage', null);

expect(events).to.have.deep.property('[2].type', 'REGISTRATION');
// expect(events).to.have.deep.property('[2].createdAt', '2012-06-17T00:00:00.000Z');
expect(events).to.have.deep.property('[2].createdAt', '16.05.2012');
expect(events).to.have.deep.property('[2].note', null);
expect(events).to.have.deep.property('[2].firstOwner', null);
expect(events).to.have.deep.property('[2].ownerType', null);
Expand All @@ -160,7 +159,7 @@ describe('events response builder test', () => {
expect(events).to.have.deep.property('[2].mileage', null);

expect(events).to.have.deep.property('[3].type', 'REGISTRATION');
// expect(events).to.have.deep.property('[3].createdAt', '2012-06-17T00:00:00.000Z');
expect(events).to.have.deep.property('[3].createdAt', '16.06.2012');
expect(events).to.have.deep.property('[3].note', null);
expect(events).to.have.deep.property('[3].firstOwner', null);
expect(events).to.have.deep.property('[3].ownerType', null);
Expand All @@ -170,17 +169,17 @@ describe('events response builder test', () => {
expect(events).to.have.deep.property('[3].mileage', null);

expect(events).to.have.deep.property('[4].type', 'INSPECTION');
// expect(events).to.have.deep.property('[4].createdAt', '2013-06-17T00:00:00.000Z');
expect(events).to.have.deep.property('[4].createdAt', '16.06.2013');
expect(events).to.have.deep.property('[4].note', null);
expect(events).to.have.deep.property('[4].firstOwner', null);
expect(events).to.have.deep.property('[4].ownerType', null);
expect(events).to.have.deep.property('[4].location', null);
// expect(events).to.have.deep.property('[4].expireAt', '2013-06-17T00:00:00.000Z');
expect(events).to.have.deep.property('[4].expireAt', '16.06.2014');
expect(events).to.have.deep.property('[4].mileage.value', 177000);
expect(events).to.have.deep.property('[4].mileage.type', 'KM');

expect(events).to.have.deep.property('[5].type', 'HOLDER');
// expect(events).to.have.deep.property('[5].createdAt', '2014-06-17T00:00:00.000Z');
expect(events).to.have.deep.property('[5].createdAt', '16.06.2013');
expect(events).to.have.deep.property('[5].note', null);
expect(events).to.have.deep.property('[5].firstOwner', null);
expect(events).to.have.deep.property('[5].ownerType', null);
Expand All @@ -190,7 +189,7 @@ describe('events response builder test', () => {
expect(events).to.have.deep.property('[5].mileage', null);

expect(events).to.have.deep.property('[6].type', 'DEREGISTRATION');
// expect(events).to.have.deep.property('[6].createdAt', '2014-06-17T00:00:00.000Z');
expect(events).to.have.deep.property('[6].createdAt', '16.06.2014');
expect(events).to.have.deep.property('[6].note', 'note');
expect(events).to.have.deep.property('[6].firstOwner', null);
expect(events).to.have.deep.property('[6].ownerType', null);
Expand All @@ -200,7 +199,7 @@ describe('events response builder test', () => {
expect(events).to.have.deep.property('[6].mileage', null);

expect(events).to.have.deep.property('[7].type', 'CO_OWNER');
// expect(events).to.have.deep.property('[7].createdAt', '2014-06-17T00:00:00.000Z');
expect(events).to.have.deep.property('[7].createdAt', '16.06.2014');
expect(events).to.have.deep.property('[7].note', null);
expect(events).to.have.deep.property('[7].firstOwner', null);
expect(events).to.have.deep.property('[7].ownerType', 'PRIVATE');
Expand All @@ -210,7 +209,7 @@ describe('events response builder test', () => {
expect(events).to.have.deep.property('[7].mileage', null);

expect(events).to.have.deep.property('[8].type', 'CHANGED_REGISTRATION_LOCATION');
// expect(events).to.have.deep.property('[8].createdAt', '2014-06-17T00:00:00.000Z');
expect(events).to.have.deep.property('[8].createdAt', '12.05.2012');
expect(events).to.have.deep.property('[8].note', null);
expect(events).to.have.deep.property('[8].firstOwner', null);
expect(events).to.have.deep.property('[8].ownerType', null);
Expand All @@ -221,7 +220,7 @@ describe('events response builder test', () => {
expect(events).to.have.deep.property('[8].mileage', null);

expect(events).to.have.deep.property('[9].type', 'STOLEN');
// expect(events).to.have.deep.property('[9].createdAt', '2014-06-17T00:00:00.000Z');
expect(events).to.have.deep.property('[9].createdAt', '12.05.2012');
expect(events).to.have.deep.property('[9].note', null);
expect(events).to.have.deep.property('[9].firstOwner', null);
expect(events).to.have.deep.property('[9].ownerType', null);
Expand Down
Loading

0 comments on commit dbfbd4b

Please sign in to comment.