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

Fix invalid date formats in tests #517

Merged
merged 3 commits into from
Jun 9, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/datewithzone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export class DateWithZone {
public tzid?: string | null

constructor(date: Date, tzid?: string | null) {
if (isNaN(date.getTime())) {
throw new RangeError('Invalid date passed to DateWithZone')
}
this.date = date
this.tzid = tzid
}
Expand Down
10 changes: 8 additions & 2 deletions test/datewithzone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ it('returns the time of the date', () => {
expect(dt.getTime()).to.equal(d.getTime())
})

it('rejects invalid dates', () => {
expect(() => new DateWithZone(new Date(undefined))).to.throw(
'Invalid date passed to DateWithZone'
)
})

describe('rezonedDate', () => {
it('returns the original date when no zone is given', () => {
const d = new Date(Date.UTC(2010, 9, 5, 11, 0, 0))
Expand All @@ -42,11 +48,11 @@ describe('rezonedDate', () => {
const currentLocalDate = new Date(2000, 1, 6, 1, 0, 0)
setMockDate(currentLocalDate)

const d = new Date(Date.parse('20101005T110000'))
const d = new Date(Date.parse('2010-10-05T11:00:00'))
const dt = new DateWithZone(d, targetZone)
expect(dt.rezonedDate()).to.deep.equal(
expectedDate(
new Date(Date.parse('20101005T110000')),
new Date(Date.parse('2010-10-05T11:00:00')),
currentLocalDate,
targetZone
)
Expand Down
20 changes: 10 additions & 10 deletions test/rruleset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,11 @@ describe('RRuleSet', function () {

set.tzid(targetZone)

set.rdate(new Date(Date.parse('20020301T090000')))
set.rdate(new Date(Date.parse('2002-03-01T09:00:00')))

expect(set.all()).to.deep.equal([
expectedDate(
new Date(Date.parse('20020301T090000')),
new Date(Date.parse('2002-03-01T09:00:00')),
currentLocalDate,
targetZone
),
Expand Down Expand Up @@ -826,8 +826,8 @@ describe('RRuleSet', function () {

describe('getters', () => {
it('rrules()', () => {
let set = new RRuleSet()
let rrule = new RRule({
const set = new RRuleSet()
const rrule = new RRule({
freq: RRule.YEARLY,
count: 2,
dtstart: parse('19600101T090000'),
Expand All @@ -839,8 +839,8 @@ describe('RRuleSet', function () {
})

it('exrules()', () => {
let set = new RRuleSet()
let rrule = new RRule({
const set = new RRuleSet()
const rrule = new RRule({
freq: RRule.YEARLY,
count: 2,
dtstart: parse('19600101T090000'),
Expand All @@ -852,16 +852,16 @@ describe('RRuleSet', function () {
})

it('rdates()', () => {
let set = new RRuleSet()
let dt = parse('19610201T090000')
const set = new RRuleSet()
const dt = parse('19610201T090000')
set.rdate(dt)

expect(set.rdates()).eql([dt])
})

it('exdates()', () => {
let set = new RRuleSet()
let dt = parse('19610201T090000')
const set = new RRuleSet()
const dt = parse('19610201T090000')
set.exdate(dt)

expect(set.exdates()).eql([dt])
Expand Down