Skip to content

Commit

Permalink
Fixed a bug (#2091)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Jun 24, 2024
1 parent d81bc8f commit 6bc514b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/jsapi-utils/src/DateUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,30 @@ describe('getJsDate', () => {
});

describe('trimDateTimeStringOverflow', () => {
it.each([
const dateTimeTexts = [
'2024',
'2012-04',
'2012-04-20',
'2012-04-20T12',
'2012-04-20T12:13',
'2012-04-20T12:13:14',
'2012-04-20T12:13:14.321',
])('should trim date time string overflow: %s', expected => {
const given = `${expected} overflow`;
const actual = DateUtils.trimDateTimeStringOverflow(given);
expect(actual).toEqual(expected);
});
];

it.each(dateTimeTexts)(
'should return given string if no overflow: %s',
given => {
const actual = DateUtils.trimDateTimeStringOverflow(given);
expect(actual).toEqual(given);
}
);

it.each(dateTimeTexts)(
'should trim date time string overflow: %s',
expected => {
const given = `${expected} overflow`;
const actual = DateUtils.trimDateTimeStringOverflow(given);
expect(actual).toEqual(expected);
}
);
});
4 changes: 4 additions & 0 deletions packages/jsapi-utils/src/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ export class DateUtils {
true
);

if (overflow === '') {
return dateTimeString;
}

return dateTimeString.slice(0, -overflow.length);
}
}
Expand Down

0 comments on commit 6bc514b

Please sign in to comment.