Skip to content

Commit

Permalink
feat(date): allow arbitrary date range [ZEND-5700] (#1806)
Browse files Browse the repository at this point in the history
  • Loading branch information
z0al authored Nov 28, 2024
1 parent 769dabb commit 9bbb2a1
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions packages/date/src/DatepickerInput.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React, { useMemo } from 'react';
import React from 'react';

import { Datepicker } from '@contentful/f36-components';
import { css } from 'emotion';
// eslint-disable-next-line -- TODO: move to date-fns
import moment from 'moment';

const YEAR_RANGE = 100;

const styles = {
root: css({
maxWidth: '270px',
Expand All @@ -20,15 +18,6 @@ export type DatePickerProps = {
};

export const DatepickerInput = (props: DatePickerProps) => {
const [fromDate, toDate] = useMemo(() => {
const fromDate = new Date();
fromDate.setFullYear(fromDate.getFullYear() - YEAR_RANGE);
const toDate = new Date();
toDate.setFullYear(toDate.getFullYear() + YEAR_RANGE);

return [fromDate, toDate];
}, []);

// The DatepickerInput should be time and timezone agnostic,
// thats why we don't use moment().toDate() to get Date object.
// moment().toDate() takes into account time and timezone and converts it
Expand All @@ -47,8 +36,6 @@ export const DatepickerInput = (props: DatePickerProps) => {
props.onChange(momentDay);
}}
inputProps={{ isDisabled: props.disabled, placeholder: '' }}
fromDate={fromDate}
toDate={toDate}
/>
);
};

0 comments on commit 9bbb2a1

Please sign in to comment.