Skip to content

Commit

Permalink
Ensure dates before 1970 work
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdemartini committed Sep 29, 2020
1 parent b6d84b2 commit 148d468
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
23 changes: 12 additions & 11 deletions packages/data-mate/test/column/column-date-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'jest-fixtures';
import { DateFormat, FieldType, Maybe } from '@terascope/types';
import formatDate from 'date-fns/format';
import { getValidDate } from '@terascope/utils';
import {
Column, ColumnTransform, DateValue, Vector
} from '../../src';
Expand All @@ -11,6 +9,7 @@ describe('Column (Date Types)', () => {
let col: Column<DateValue>;
const values: Maybe<any>[] = [
'2020-09-23T14:54:21.020Z',
'1941-08-20T07:00:00.000Z',
'2020-09-23',
1600875138416,
null,
Expand Down Expand Up @@ -62,23 +61,25 @@ describe('Column (Date Types)', () => {
}));
});

it('should be able to transform using formatDate(format: "pP")', () => {
it('should be able to transform using formatDate(format: "yyyy-MM-dd HH:mm:ss")', () => {
const newCol = col.transform(ColumnTransform.formatDate, {
format: 'Pp'
format: 'yyyy-MM-dd HH:mm:ss'
});

expect(newCol.id).not.toBe(col.id);
expect(newCol.config).toEqual({
...col.config,
format: 'Pp',
format: 'yyyy-MM-dd HH:mm:ss',
type: FieldType.Date
});
expect(newCol.toJSON()).toEqual(values.map((value) => {
if (value == null) return null;
const date = getValidDate(value);
if (date === false) return false;
return formatDate(date, 'Pp');
}));
expect(newCol.toJSON()).toEqual([
'2020-09-23 07:54:21',
'1941-08-20 00:00:00',
'2020-09-22 17:00:00',
'2020-09-23 08:32:18',
null,
'2019-01-20 05:50:20',
]);
});

test.todo('should NOT able to transform without using formatDate()');
Expand Down
3 changes: 2 additions & 1 deletion packages/data-mate/test/vector/vector-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ describe('Vector', () => {
],
[
FieldType.Date,
[nowDate, nowDate.toISOString(), now, null, undefined],
[nowDate, nowDate.toISOString(), now, '1941-08-20T07:00:00.000Z', null, undefined],
[
nowDate.toISOString(),
nowDate.toISOString(),
nowDate.toISOString(),
'1941-08-20T07:00:00.000Z',
null,
null
]
Expand Down

0 comments on commit 148d468

Please sign in to comment.