Skip to content

Commit

Permalink
feat(datepicker): added resolve to UTC switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukeybooi committed Jul 18, 2023
1 parent ec58b2f commit 1d33ee6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getMoment, getPropertyMetadata } from '../../utils/date';
import { axiosHttp } from '../../utils/fetchers';
import { IDateFieldProps, IRangeInfo, RangePickerChangeEvent, TimePickerChangeEvent } from './interfaces';
import settingsFormJson from './settingsForm.json';
import { DATE_TIME_FORMATS, disabledDate, getFormat, getRangePickerValues } from './utils';
import { DATE_TIME_FORMATS, disabledDate, getDefaultFormat, getFormat, getRangePickerValues } from './utils';

const META_DATA_FILTERS: ProperyDataType[] = ['date', 'date-time', 'time'];

Expand Down Expand Up @@ -116,7 +116,7 @@ export const DatePickerWrapper: FC<IDateFieldProps> = (props) => {
const dateFormat = props?.dateFormat || getPropertyMetadata(properties, name) || DATE_TIME_FORMATS.date;
const timeFormat = props?.timeFormat || DATE_TIME_FORMATS.time;

const defaultFormat = dateOnly ? 'YYYY-MM-DD' : null;
const defaultFormat = getDefaultFormat(props);

const { form, formMode, isComponentDisabled, formData } = useForm();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IDateFieldProps extends IConfigurableFormComponent {
weekFormat?: string;
range?: boolean;
dateOnly?: boolean;
resolveToUTC?: boolean;
picker?: 'time' | 'date' | 'week' | 'month' | 'quarter' | 'year';
disablePastDates?: boolean;
onChange?: TimePickerChangeEvent | RangePickerChangeEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
"label": "Date Only?",
"description": "Send only a date format as a request, otherwise sends a datetime format"
},
{
"id": "e92bcf3c-a70a-4aeb-b6ac-5643eb5b4fe2",
"type": "switch",
"name": "resolveToUTC",
"parentId": "VmAusRlLZo3cYRFk88xnf",
"label": "Resolve to UTC",
"description": "If switched on the selected time will be converted to UTC"
},
{
"id": "57a40a33-7e08-4ce4-9f08-a34d24a83338",
"type": "dropdown",
Expand Down
12 changes: 12 additions & 0 deletions shesha-reactjs/src/designer-components/dateField/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ export function disabledDate(props: IDateFieldProps, current) {
return disabledFunc(current, moment);
}

export const getDefaultFormat = ({ dateOnly, resolveToUTC }: IDateFieldProps) => {
if (dateOnly) {
return 'YYYY-MM-DD';
}

if (!resolveToUTC) {
return 'YYYY-MM-DDThh:mm:ss';
}

return null;
};

export const getFormat = (props: IDateFieldProps, properties: IPropertyMetadata[]) => {
const { name, picker, showTime } = props || {};

Expand Down

0 comments on commit 1d33ee6

Please sign in to comment.