Skip to content
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
17 changes: 12 additions & 5 deletions packages/@internationalized/date/src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {Mutable} from './utils';
const TIME_RE = /^(\d{2})(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?$/;
const DATE_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})$/;
const DATE_TIME_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?$/;
const ZONED_DATE_TIME_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:([+-]\d{2})(?::?(\d{2}))?)?\[(.*?)\]$/;
const ZONED_DATE_TIME_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:([+-]\d{2})(?::?(\d{2}))?(?::?(\d{2}))?)?\[(.*?)\]$/;
const ABSOLUTE_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:(?:([+-]\d{2})(?::?(\d{2}))?)|Z)$/;
const DATE_TIME_DURATION_RE =
/^((?<negative>-)|\+)?P((?<years>\d*)Y)?((?<months>\d*)M)?((?<weeks>\d*)W)?((?<days>\d*)D)?((?<time>T)((?<hours>\d*[.,]?\d{1,9})H)?((?<minutes>\d*[.,]?\d{1,9})M)?((?<seconds>\d*[.,]?\d{1,9})S)?)?$/;
Expand Down Expand Up @@ -104,7 +104,7 @@ export function parseZonedDateTime(value: string, disambiguation?: Disambiguatio
year < 1 ? -year + 1 : year,
parseNumber(m[2], 1, 12),
1,
m[10],
m[11],
0,
m[4] ? parseNumber(m[4], 0, 23) : 0,
m[5] ? parseNumber(m[5], 0, 59) : 0,
Expand All @@ -118,7 +118,8 @@ export function parseZonedDateTime(value: string, disambiguation?: Disambiguatio

let ms: number;
if (m[8]) {
date.offset = parseNumber(m[8], -23, 23) * 60 * 60 * 1000 + parseNumber(m[9] ?? '0', 0, 59) * 60 * 1000;
let hourOffset = parseNumber(m[8], -23, 23);
date.offset = Math.sign(hourOffset) * (Math.abs(hourOffset) * 60 * 60 * 1000 + parseNumber(m[9] ?? '0', 0, 59) * 60 * 1000 + parseNumber(m[10] ?? '0', 0, 59) * 1000);
ms = epochFromDate(date as ZonedDateTime) - date.offset;

// Validate offset against parsed date.
Expand Down Expand Up @@ -212,8 +213,14 @@ function offsetToString(offset: number) {
let sign = Math.sign(offset) < 0 ? '-' : '+';
offset = Math.abs(offset);
let offsetHours = Math.floor(offset / (60 * 60 * 1000));
let offsetMinutes = (offset % (60 * 60 * 1000)) / (60 * 1000);
return `${sign}${String(offsetHours).padStart(2, '0')}:${String(offsetMinutes).padStart(2, '0')}`;
let offsetMinutes = Math.floor((offset % (60 * 60 * 1000)) / (60 * 1000));
let offsetSeconds = Math.floor((offset % (60 * 60 * 1000)) % (60 * 1000) / 1000);
let stringOffset = `${sign}${String(offsetHours).padStart(2, '0')}:${String(offsetMinutes).padStart(2, '0')}`;
if (offsetSeconds !== 0) {
stringOffset += `:${String(offsetSeconds).padStart(2, '0')}`;
}

return stringOffset;
}

export function zonedDateTimeToString(date: ZonedDateTime): string {
Expand Down
7 changes: 7 additions & 0 deletions packages/@internationalized/date/tests/string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ describe('string conversion', function () {
expect(() => parseZonedDateTime('2020-02-03T23:99[America/Los_Angeles]')).toThrow();
expect(() => parseZonedDateTime('2020-02-03T12:22:99[America/Los_Angeles]')).toThrow();
});

it('should parse dates with seconds in offset', function () {
let date = parseZonedDateTime('1883-11-07T00:45[America/Los_Angeles]');
let string = date.toString(); // => "1883-11-07T00:45:00-07:52:58[America/Los_Angeles]"
let parseBack = parseZonedDateTime(string);
expect(parseBack).toEqual(date);
});
});

describe('ZonedDateTime#toString', function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-spectrum/s2/src/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface DialogProps extends Omit<RACDialogProps, 'className' | 'style'
*
* @default 'M'
*/
size?: 'S' | 'M' | 'L',
size?: 'S' | 'M' | 'L' | 'XL',
/** Whether pressing the escape key to close the dialog should be disabled. */
isKeyboardDismissDisabled?: boolean
}
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-spectrum/s2/src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface ModalProps extends ModalOverlayProps {
*
* @default 'M'
*/
size?: 'S' | 'M' | 'L' | 'fullscreen' | 'fullscreenTakeover'
size?: 'S' | 'M' | 'L' | 'XL' | 'fullscreen' | 'fullscreenTakeover'
}

const modalOverlayStyles = style({
Expand Down Expand Up @@ -103,6 +103,7 @@ export const Modal = forwardRef(function Modal(props: ModalProps, ref: DOMRef<HT
S: 400,
M: 480,
L: 640,
XL: 960,
fullscreen: 'calc(100% - 40px)',
fullscreenTakeover: 'full'
}
Expand Down
Loading