Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Temporal objects #88

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ function extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandTyp
return entriesEqual(leftHandOperand, rightHandOperand, options);
case 'Map':
return entriesEqual(leftHandOperand, rightHandOperand, options);
case 'Temporal.PlainDate':
case 'Temporal.PlainTime':
case 'Temporal.PlainDateTime':
case 'Temporal.Instant':
case 'Temporal.ZonedDateTime':
case 'Temporal.PlainYearMonth':
case 'Temporal.PlainMonthDay':
return leftHandOperand.equals(rightHandOperand);
case 'Temporal.Duration':
return leftHandOperand.total('nanoseconds') === rightHandOperand.total('nanoseconds');
case 'Temporal.TimeZone':
case 'Temporal.Calendar':
return leftHandOperand.toString() === rightHandOperand.toString();
default:
return objectEqual(leftHandOperand, rightHandOperand, options);
}
Expand Down
44 changes: 40 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"type-detect": "^4.0.0"
},
"devDependencies": {
"@js-temporal/polyfill": "^0.4.1",
"benchmark": "^2.1.0",
"browserify": "^17.0.0",
"browserify-istanbul": "^3.0.1",
Expand Down
135 changes: 135 additions & 0 deletions test/temporal-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
'use strict';

var assert = require('simple-assert');
var { Temporal } = require('@js-temporal/polyfill');
var eql = require('..');

describe('TC39 Temporal', function () {
describe('Temporal.PlainDate', function () {
it('returns true for same dates', function () {
assert(eql(new Temporal.PlainDate(2022, 1, 1), new Temporal.PlainDate(2022, 1, 1)),
'eql(new Temporal.PlainDate(2022, 1, 1), new Temporal.PlainDate(2022, 1, 1))');
});

it('returns false for different dates', function () {
assert(eql(new Temporal.PlainDate(2022, 1, 1), new Temporal.PlainDate(2022, 1, 2)) === false,
'eql(new Temporal.PlainDate(2022, 1, 1), new Temporal.PlainDate(2022, 1, 2)) === false');
});
});

describe('Temporal.PlainTime', function () {
it('returns true for same times', function () {
assert(eql(new Temporal.PlainTime(12, 0, 0), new Temporal.PlainTime(12, 0, 0)),
'eql(new Temporal.PlainTime(12, 0, 0), new Temporal.PlainTime(12, 0, 0))');
});

it('returns false for different times', function () {
assert(eql(new Temporal.PlainTime(12, 0, 0), new Temporal.PlainTime(13, 0, 0)) === false,
'eql(new Temporal.PlainTime(12, 0, 0), new Temporal.PlainTime(13, 0, 0)) === false');
});
});

describe('Temporal.PlainDateTime', function () {
it('returns true for same date times', function () {
assert(eql(new Temporal.PlainDateTime(2022, 1, 1, 12, 0, 0), new Temporal.PlainDateTime(2022, 1, 1, 12, 0, 0)),
'eql(new Temporal.PlainDateTime(2022, 1, 1, 12, 0, 0), new Temporal.PlainDateTime(2022, 1, 1, 12, 0, 0))');
});

it('returns false for different date times', function () {
assert(eql(new Temporal.PlainDateTime(2022, 1, 1, 12, 0, 0),
new Temporal.PlainDateTime(2022, 1, 1, 13, 0, 0)) === false,
// eslint-disable-next-line max-len
'eql(new Temporal.PlainDateTime(2022, 1, 1, 12, 0, 0), new Temporal.PlainDateTime(2022, 1, 1, 13, 0, 0)) === false');
});
});

describe('Temporal.Instant', function () {
it('returns true for same instants', function () {
assert(eql(Temporal.Instant.from('2022-01-01T12:00:00.000Z'), Temporal.Instant.from('2022-01-01T12:00:00.000Z')),
'eql(Temporal.Instant.from("2022-01-01T12:00:00.000Z"), Temporal.Instant.from("2022-01-01T12:00:00.000Z"))');
});

it('returns false for different instants', function () {
assert(eql(Temporal.Instant.from('2022-01-01T12:00:00.000Z'),
Temporal.Instant.from('2022-01-01T13:00:00.000Z')) === false,
// eslint-disable-next-line max-len
'eql(Temporal.Instant.from("2022-01-01T12:00:00.000Z"), Temporal.Instant.from("2022-01-01T13:00:00.000Z")) === false');
});
});

describe('Temporal.ZonedDateTime', function () {
it('returns true for same zoned date times', function () {
assert(eql(Temporal.ZonedDateTime.from('2022-01-01T12:00:00.000Z[+01:00]'),
Temporal.ZonedDateTime.from('2022-01-01T12:00:00.000Z[+01:00]')),
// eslint-disable-next-line max-len
'eql(Temporal.ZonedDateTime.from("2022-01-01T12:00:00.000Z[+01:00]"), Temporal.ZonedDateTime.from("2022-01-01T12:00:00.000Z[+01:00]"))');
});

it('returns false for different zoned date times', function () {
assert(eql(Temporal.ZonedDateTime.from('2022-01-01T12:00:00.000Z[+01:00]'),
Temporal.ZonedDateTime.from('2022-01-01T13:00:00.000Z[+01:00]')) === false,
// eslint-disable-next-line max-len
'eql(Temporal.ZonedDateTime.from("2022-01-01T12:00:00.000Z[+01:00]"), Temporal.ZonedDateTime.from("2022-01-01T13:00:00.000Z[+01:00]")) === false');
});
});

describe('Temporal.PlainYearMonth', function () {
it('returns true for same plain year months', function () {
assert(eql(new Temporal.PlainYearMonth(2022, 1), new Temporal.PlainYearMonth(2022, 1)),
'eql(new Temporal.PlainYearMonth(2022, 1), new Temporal.PlainYearMonth(2022, 1))');
});

it('returns false for different plain year months', function () {
assert(eql(new Temporal.PlainYearMonth(2022, 1), new Temporal.PlainYearMonth(2022, 2)) === false,
'eql(new Temporal.PlainYearMonth(2022, 1), new Temporal.PlainYearMonth(2022, 2)) === false');
});
});

describe('Temporal.PlainMonthDay', function () {
it('returns true for same plain month days', function () {
assert(eql(new Temporal.PlainMonthDay(1, 1), new Temporal.PlainMonthDay(1, 1)),
'eql(new Temporal.PlainMonthDay(1, 1), new Temporal.PlainMonthDay(1, 1))');
});

it('returns false for different plain month days', function () {
assert(eql(new Temporal.PlainMonthDay(1, 1), new Temporal.PlainMonthDay(2, 1)) === false,
'eql(new Temporal.PlainMonthDay(1, 1), new Temporal.PlainMonthDay(2, 1)) === false');
});
});

describe('Temporal.Duration', function () {
it('returns true for same durations', function () {
assert(eql(new Temporal.Duration(0, 0, 0, 1), new Temporal.Duration(0, 0, 0, 1)),
'eql(new Temporal.Duration(0, 0, 0, 1), new Temporal.Duration(0, 0, 0, 1))');
});

it('returns false for different durations', function () {
assert(eql(new Temporal.Duration(0, 0, 0, 1), new Temporal.Duration(0, 0, 0, 2)) === false,
'eql(new Temporal.Duration(0, 0, 0, 1), new Temporal.Duration(0, 0, 0, 2)) === false');
});
});

describe('Temporal.TimeZone', function () {
it('returns true for same time zones', function () {
assert(eql(new Temporal.TimeZone('+01:00'), new Temporal.TimeZone('+01:00')),
'eql(new Temporal.TimeZone("+01:00"), new Temporal.TimeZone("+01:00"))');
});

it('returns false for different time zones', function () {
assert(eql(new Temporal.TimeZone('+01:00'), new Temporal.TimeZone('+02:00')) === false,
'eql(new Temporal.TimeZone("+01:00"), new Temporal.TimeZone("+02:00")) === false');
});
});

describe('Temporal.Calendar', function () {
it('returns true for same calendars', function () {
assert(eql(new Temporal.Calendar('gregory'), new Temporal.Calendar('gregory')),
'eql(new Temporal.Calendar("gregory"), new Temporal.Calendar("gregory"))');
});

it('returns false for different calendars', function () {
assert(eql(new Temporal.Calendar('gregory'), new Temporal.Calendar('iso8601')) === false,
'eql(new Temporal.Calendar("gregory"), new Temporal.Calendar("iso8601")) === false');
});
});
});