Skip to content

Commit 6bc514b

Browse files
committed
Fixed a bug (#2091)
1 parent d81bc8f commit 6bc514b

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

packages/jsapi-utils/src/DateUtils.test.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,17 +450,30 @@ describe('getJsDate', () => {
450450
});
451451

452452
describe('trimDateTimeStringOverflow', () => {
453-
it.each([
453+
const dateTimeTexts = [
454454
'2024',
455455
'2012-04',
456456
'2012-04-20',
457457
'2012-04-20T12',
458458
'2012-04-20T12:13',
459459
'2012-04-20T12:13:14',
460460
'2012-04-20T12:13:14.321',
461-
])('should trim date time string overflow: %s', expected => {
462-
const given = `${expected} overflow`;
463-
const actual = DateUtils.trimDateTimeStringOverflow(given);
464-
expect(actual).toEqual(expected);
465-
});
461+
];
462+
463+
it.each(dateTimeTexts)(
464+
'should return given string if no overflow: %s',
465+
given => {
466+
const actual = DateUtils.trimDateTimeStringOverflow(given);
467+
expect(actual).toEqual(given);
468+
}
469+
);
470+
471+
it.each(dateTimeTexts)(
472+
'should trim date time string overflow: %s',
473+
expected => {
474+
const given = `${expected} overflow`;
475+
const actual = DateUtils.trimDateTimeStringOverflow(given);
476+
expect(actual).toEqual(expected);
477+
}
478+
);
466479
});

packages/jsapi-utils/src/DateUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ export class DateUtils {
394394
true
395395
);
396396

397+
if (overflow === '') {
398+
return dateTimeString;
399+
}
400+
397401
return dateTimeString.slice(0, -overflow.length);
398402
}
399403
}

0 commit comments

Comments
 (0)