utc 逻辑整理, 只存储用 utc,显示还是当地时间

This commit is contained in:
2betop 2020-02-21 21:20:26 +08:00
parent 4cd296ee6d
commit 58892153d0
5 changed files with 146 additions and 152 deletions

View File

@ -211,8 +211,6 @@ export interface DateProps {
disabled?: boolean; disabled?: boolean;
minDate?: moment.Moment; minDate?: moment.Moment;
maxDate?: moment.Moment; maxDate?: moment.Moment;
minTime?: moment.Moment;
maxTime?: moment.Moment;
clearable?: boolean; clearable?: boolean;
defaultValue?: any; defaultValue?: any;
utc?: boolean; utc?: boolean;

View File

@ -4,18 +4,18 @@
* @author fex * @author fex
*/ */
import React = require("react"); import React = require('react');
import moment = require("moment"); import moment = require('moment');
import { findDOMNode } from "react-dom"; import {findDOMNode} from 'react-dom';
import cx from "classnames"; import cx from 'classnames';
import { Icon } from "./icons"; import {Icon} from './icons';
import Overlay from "./Overlay"; import Overlay from './Overlay';
import { ShortCuts, ShortCutDateRange } from "./DatePicker"; import {ShortCuts, ShortCutDateRange} from './DatePicker';
import Calendar from "./calendar/Calendar"; import Calendar from './calendar/Calendar';
import PopOver from "./PopOver"; import PopOver from './PopOver';
import { ClassNamesFn, themeable } from "../theme"; import {ClassNamesFn, themeable} from '../theme';
import { PlainObject } from "../types"; import {PlainObject} from '../types';
import { noop } from "../utils/helper"; import {noop} from '../utils/helper';
export interface DateRangePickerProps { export interface DateRangePickerProps {
className?: string; className?: string;
@ -24,6 +24,7 @@ export interface DateRangePickerProps {
placeholder?: string; placeholder?: string;
theme?: any; theme?: any;
format: string; format: string;
utc?: boolean;
inputFormat?: string; inputFormat?: string;
ranges?: string | Array<ShortCuts>; ranges?: string | Array<ShortCuts>;
clearable?: boolean; clearable?: boolean;
@ -48,110 +49,110 @@ export interface DateRangePickerState {
endDate?: moment.Moment; endDate?: moment.Moment;
} }
const availableRanges: { [propName: string]: any } = { const availableRanges: {[propName: string]: any} = {
today: { 'today': {
label: "今天", label: '今天',
startDate: (now: moment.Moment) => { startDate: (now: moment.Moment) => {
return now.startOf("day"); return now.startOf('day');
}, },
endDate: (now: moment.Moment) => { endDate: (now: moment.Moment) => {
return now; return now;
} }
}, },
yesterday: { 'yesterday': {
label: "昨天", label: '昨天',
startDate: (now: moment.Moment) => { startDate: (now: moment.Moment) => {
return now.add(-1, "days").startOf("day"); return now.add(-1, 'days').startOf('day');
}, },
endDate: (now: moment.Moment) => { endDate: (now: moment.Moment) => {
return now.add(-1, "days").endOf("day"); return now.add(-1, 'days').endOf('day');
} }
}, },
"1dayago": { '1dayago': {
label: "最近1天", label: '最近1天',
startDate: (now: moment.Moment) => { startDate: (now: moment.Moment) => {
return now.add(-1, "days"); return now.add(-1, 'days');
}, },
endDate: (now: moment.Moment) => { endDate: (now: moment.Moment) => {
return now; return now;
} }
}, },
"7daysago": { '7daysago': {
label: "最近7天", label: '最近7天',
startDate: (now: moment.Moment) => { startDate: (now: moment.Moment) => {
return now.add(-7, "days").startOf("day"); return now.add(-7, 'days').startOf('day');
}, },
endDate: (now: moment.Moment) => { endDate: (now: moment.Moment) => {
return now.add(-1, "days").endOf("day"); return now.add(-1, 'days').endOf('day');
} }
}, },
"90daysago": { '90daysago': {
label: "最近90天", label: '最近90天',
startDate: (now: moment.Moment) => { startDate: (now: moment.Moment) => {
return now.add(-90, "days").startOf("day"); return now.add(-90, 'days').startOf('day');
}, },
endDate: (now: moment.Moment) => { endDate: (now: moment.Moment) => {
return now.add(-1, "days").endOf("day"); return now.add(-1, 'days').endOf('day');
} }
}, },
prevweek: { 'prevweek': {
label: "上周", label: '上周',
startDate: (now: moment.Moment) => { startDate: (now: moment.Moment) => {
return now.startOf("week").add(-1, "weeks"); return now.startOf('week').add(-1, 'weeks');
}, },
endDate: (now: moment.Moment) => { endDate: (now: moment.Moment) => {
return now return now
.startOf("week") .startOf('week')
.add(-1, "days") .add(-1, 'days')
.endOf("day"); .endOf('day');
} }
}, },
thismonth: { 'thismonth': {
label: "本月", label: '本月',
startDate: (now: moment.Moment) => { startDate: (now: moment.Moment) => {
return now.startOf("month"); return now.startOf('month');
}, },
endDate: (now: moment.Moment) => { endDate: (now: moment.Moment) => {
return now; return now;
} }
}, },
prevmonth: { 'prevmonth': {
label: "上个月", label: '上个月',
startDate: (now: moment.Moment) => { startDate: (now: moment.Moment) => {
return now.startOf("month").add(-1, "month"); return now.startOf('month').add(-1, 'month');
}, },
endDate: (now: moment.Moment) => { endDate: (now: moment.Moment) => {
return now return now
.startOf("month") .startOf('month')
.add(-1, "day") .add(-1, 'day')
.endOf("day"); .endOf('day');
} }
}, },
prevquarter: { 'prevquarter': {
label: "上个季节", label: '上个季节',
startDate: (now: moment.Moment) => { startDate: (now: moment.Moment) => {
return now.startOf("quarter").add(-1, "quarter"); return now.startOf('quarter').add(-1, 'quarter');
}, },
endDate: (now: moment.Moment) => { endDate: (now: moment.Moment) => {
return now return now
.startOf("quarter") .startOf('quarter')
.add(-1, "day") .add(-1, 'day')
.endOf("day"); .endOf('day');
} }
}, },
thisquarter: { 'thisquarter': {
label: "本季度", label: '本季度',
startDate: (now: moment.Moment) => { startDate: (now: moment.Moment) => {
return now.startOf("quarter"); return now.startOf('quarter');
}, },
endDate: (now: moment.Moment) => { endDate: (now: moment.Moment) => {
return now; return now;
@ -164,17 +165,17 @@ export class DateRangePicker extends React.Component<
DateRangePickerState DateRangePickerState
> { > {
static defaultProps = { static defaultProps = {
placeholder: "请选择日期范围", placeholder: '请选择日期范围',
format: "X", format: 'X',
inputFormat: "YYYY-MM-DD", inputFormat: 'YYYY-MM-DD',
joinValues: true, joinValues: true,
clearable: true, clearable: true,
delimiter: ",", delimiter: ',',
ranges: "yesterday,7daysago,prevweek,thismonth,prevmonth,prevquarter", ranges: 'yesterday,7daysago,prevweek,thismonth,prevmonth,prevquarter',
iconClassName: "fa fa-calendar", iconClassName: 'fa fa-calendar',
resetValue: "", resetValue: '',
closeOnSelect: true, closeOnSelect: true,
overlayPlacement: "auto" overlayPlacement: 'auto'
}; };
innerDom: any; innerDom: any;
@ -185,11 +186,14 @@ export class DateRangePicker extends React.Component<
newValue: any, newValue: any,
format: string, format: string,
joinValues: boolean, joinValues: boolean,
delimiter: string delimiter: string,
utc = false
) { ) {
newValue = [ newValue = [
newValue.startDate.format(format), (utc ? moment.utc(newValue.startDate) : newValue.startDate).format(
newValue.endDate.format(format) format
),
(utc ? moment.utc(newValue.endDate) : newValue.endDate).format(format)
]; ];
if (joinValues) { if (joinValues) {
@ -212,7 +216,7 @@ export class DateRangePicker extends React.Component<
}; };
} }
if (joinValues && typeof value === "string") { if (joinValues && typeof value === 'string') {
value = value.split(delimiter); value = value.split(delimiter);
} }
@ -223,7 +227,7 @@ export class DateRangePicker extends React.Component<
} }
dom: React.RefObject<HTMLDivElement>; dom: React.RefObject<HTMLDivElement>;
nextMonth = moment().add(1, "months"); nextMonth = moment().add(1, 'months');
constructor(props: DateRangePickerProps) { constructor(props: DateRangePickerProps) {
super(props); super(props);
@ -243,7 +247,7 @@ export class DateRangePicker extends React.Component<
this.handleKeyPress = this.handleKeyPress.bind(this); this.handleKeyPress = this.handleKeyPress.bind(this);
this.handlePopOverClick = this.handlePopOverClick.bind(this); this.handlePopOverClick = this.handlePopOverClick.bind(this);
this.renderDay = this.renderDay.bind(this); this.renderDay = this.renderDay.bind(this);
const { format, joinValues, delimiter, value } = this.props; const {format, joinValues, delimiter, value} = this.props;
this.state = { this.state = {
isOpened: false, isOpened: false,
@ -254,7 +258,7 @@ export class DateRangePicker extends React.Component<
componentWillReceiveProps(nextProps: DateRangePickerProps) { componentWillReceiveProps(nextProps: DateRangePickerProps) {
const props = this.props; const props = this.props;
const { value, format, joinValues, delimiter } = nextProps; const {value, format, joinValues, delimiter} = nextProps;
if (props.value !== value) { if (props.value !== value) {
this.setState({ this.setState({
@ -320,7 +324,7 @@ export class DateRangePicker extends React.Component<
} }
handleKeyPress(e: React.KeyboardEvent) { handleKeyPress(e: React.KeyboardEvent) {
if (e.key === " ") { if (e.key === ' ') {
this.handleClick(); this.handleClick();
} }
} }
@ -340,7 +344,8 @@ export class DateRangePicker extends React.Component<
}, },
this.props.format, this.props.format,
this.props.joinValues, this.props.joinValues,
this.props.delimiter this.props.delimiter,
this.props.utc
) )
); );
this.close(); this.close();
@ -365,7 +370,7 @@ export class DateRangePicker extends React.Component<
handleEndChange(newValue: moment.Moment) { handleEndChange(newValue: moment.Moment) {
newValue = newValue =
!this.state.endDate && !this.props.timeFormat !this.state.endDate && !this.props.timeFormat
? newValue.endOf("day") ? newValue.endOf('day')
: newValue; : newValue;
if ( if (
@ -384,7 +389,7 @@ export class DateRangePicker extends React.Component<
} }
selectRannge(range: PlainObject) { selectRannge(range: PlainObject) {
const { closeOnSelect } = this.props; const {closeOnSelect} = this.props;
const now = moment(); const now = moment();
this.setState( this.setState(
{ {
@ -399,10 +404,10 @@ export class DateRangePicker extends React.Component<
if (!ranges) { if (!ranges) {
return null; return null;
} }
const { classPrefix: ns } = this.props; const {classPrefix: ns} = this.props;
let rangeArr: Array<string | ShortCuts>; let rangeArr: Array<string | ShortCuts>;
if (typeof ranges === "string") { if (typeof ranges === 'string') {
rangeArr = ranges.split(","); rangeArr = ranges.split(',');
} else { } else {
rangeArr = ranges; rangeArr = ranges;
} }
@ -413,7 +418,7 @@ export class DateRangePicker extends React.Component<
return null; return null;
} }
let range: PlainObject = {}; let range: PlainObject = {};
if (typeof item === "string") { if (typeof item === 'string') {
range = availableRanges[item]; range = availableRanges[item];
range.key = item; range.key = item;
} else if ( } else if (
@ -443,15 +448,15 @@ export class DateRangePicker extends React.Component<
clearValue(e: React.MouseEvent<any>) { clearValue(e: React.MouseEvent<any>) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
const { resetValue, onChange } = this.props; const {resetValue, onChange} = this.props;
onChange(resetValue); onChange(resetValue);
} }
checkStartIsValidDate(currentDate: moment.Moment) { checkStartIsValidDate(currentDate: moment.Moment) {
let { endDate } = this.state; let {endDate} = this.state;
let { minDate, maxDate } = this.props; let {minDate, maxDate} = this.props;
maxDate = maxDate =
maxDate && endDate maxDate && endDate
@ -460,9 +465,9 @@ export class DateRangePicker extends React.Component<
: endDate : endDate
: maxDate || endDate; : maxDate || endDate;
if (minDate && currentDate.isBefore(minDate, "day")) { if (minDate && currentDate.isBefore(minDate, 'day')) {
return false; return false;
} else if (maxDate && currentDate.isAfter(maxDate, "day")) { } else if (maxDate && currentDate.isAfter(maxDate, 'day')) {
return false; return false;
} }
@ -470,9 +475,9 @@ export class DateRangePicker extends React.Component<
} }
checkEndIsValidDate(currentDate: moment.Moment) { checkEndIsValidDate(currentDate: moment.Moment) {
let { startDate } = this.state; let {startDate} = this.state;
let { minDate, maxDate } = this.props; let {minDate, maxDate} = this.props;
minDate = minDate =
minDate && startDate minDate && startDate
@ -481,9 +486,9 @@ export class DateRangePicker extends React.Component<
: startDate : startDate
: minDate || startDate; : minDate || startDate;
if (minDate && currentDate.isBefore(minDate, "day")) { if (minDate && currentDate.isBefore(minDate, 'day')) {
return false; return false;
} else if (maxDate && currentDate.isAfter(maxDate, "day")) { } else if (maxDate && currentDate.isAfter(maxDate, 'day')) {
return false; return false;
} }
@ -491,14 +496,14 @@ export class DateRangePicker extends React.Component<
} }
renderDay(props: any, currentDate: moment.Moment) { renderDay(props: any, currentDate: moment.Moment) {
let { startDate, endDate } = this.state; let {startDate, endDate} = this.state;
if ( if (
startDate && startDate &&
endDate && endDate &&
currentDate.isBetween(startDate, endDate, "day", "[]") currentDate.isBetween(startDate, endDate, 'day', '[]')
) { ) {
props.className += " rdtBetween"; props.className += ' rdtBetween';
} }
return <td {...props}>{currentDate.date()}</td>; return <td {...props}>{currentDate.date()}</td>;
@ -513,6 +518,7 @@ export class DateRangePicker extends React.Component<
popOverContainer, popOverContainer,
inputFormat, inputFormat,
format, format,
dateFormat,
joinValues, joinValues,
delimiter, delimiter,
clearable, clearable,
@ -523,7 +529,7 @@ export class DateRangePicker extends React.Component<
overlayPlacement overlayPlacement
} = this.props; } = this.props;
const { isOpened, isFocused, startDate, endDate } = this.state; const {isOpened, isFocused, startDate, endDate} = this.state;
const selectedDate = DateRangePicker.unFormatValue( const selectedDate = DateRangePicker.unFormatValue(
value, value,
@ -533,10 +539,10 @@ export class DateRangePicker extends React.Component<
); );
const startViewValue = selectedDate.startDate const startViewValue = selectedDate.startDate
? selectedDate.startDate.format(inputFormat) ? selectedDate.startDate.format(inputFormat)
: ""; : '';
const endViewValue = selectedDate.endDate const endViewValue = selectedDate.endDate
? selectedDate.endDate.format(inputFormat) ? selectedDate.endDate.format(inputFormat)
: ""; : '';
const arr = []; const arr = [];
startViewValue && arr.push(startViewValue); startViewValue && arr.push(startViewValue);
endViewValue && arr.push(endViewValue); endViewValue && arr.push(endViewValue);
@ -550,8 +556,8 @@ export class DateRangePicker extends React.Component<
className={cx( className={cx(
`${ns}DateRangePicker`, `${ns}DateRangePicker`,
{ {
"is-disabled": disabled, 'is-disabled': disabled,
"is-focused": isFocused 'is-focused': isFocused
}, },
className className
)} )}
@ -560,7 +566,7 @@ export class DateRangePicker extends React.Component<
> >
{arr.length ? ( {arr.length ? (
<span className={`${ns}DateRangePicker-value`}> <span className={`${ns}DateRangePicker-value`}>
{arr.join(" 至 ")} {arr.join(' 至 ')}
</span> </span>
) : ( ) : (
<span className={`${ns}DateRangePicker-placeholder`}> <span className={`${ns}DateRangePicker-placeholder`}>
@ -602,7 +608,7 @@ export class DateRangePicker extends React.Component<
value={startDate} value={startDate}
onChange={this.handleStartChange} onChange={this.handleStartChange}
requiredConfirm={false} requiredConfirm={false}
dateFormat={format} dateFormat={dateFormat}
timeFormat={timeFormat} timeFormat={timeFormat}
isValidDate={this.checkStartIsValidDate} isValidDate={this.checkStartIsValidDate}
viewMode="days" viewMode="days"
@ -616,7 +622,7 @@ export class DateRangePicker extends React.Component<
value={endDate} value={endDate}
onChange={this.handleEndChange} onChange={this.handleEndChange}
requiredConfirm={false} requiredConfirm={false}
dateFormat={format} dateFormat={dateFormat}
timeFormat={timeFormat} timeFormat={timeFormat}
viewDate={this.nextMonth} viewDate={this.nextMonth}
isEndDate isEndDate
@ -629,8 +635,8 @@ export class DateRangePicker extends React.Component<
<div key="button" className={`${ns}DateRangePicker-actions`}> <div key="button" className={`${ns}DateRangePicker-actions`}>
<a <a
className={cx("rdtBtn rdtBtnConfirm", { className={cx('rdtBtn rdtBtnConfirm', {
"is-disabled": 'is-disabled':
!this.state.startDate || !this.state.endDate !this.state.startDate || !this.state.endDate
})} })}
onClick={this.confirm} onClick={this.confirm}

View File

@ -18,15 +18,11 @@ export interface DateProps extends FormControlProps {
utc?: boolean; // 设定是否存储 utc 时间。 utc?: boolean; // 设定是否存储 utc 时间。
minDate?: string; minDate?: string;
maxDate?: string; maxDate?: string;
maxTime?: string;
minTime?: string;
} }
interface DateControlState { interface DateControlState {
minDate?: moment.Moment; minDate?: moment.Moment;
maxDate?: moment.Moment; maxDate?: moment.Moment;
minTime?: moment.Moment;
maxTime?: moment.Moment;
} }
export default class DateControl extends React.PureComponent< export default class DateControl extends React.PureComponent<
@ -50,9 +46,6 @@ export default class DateControl extends React.PureComponent<
const { const {
minDate, minDate,
maxDate, maxDate,
maxTime,
minTime,
timeFormat,
value, value,
defaultValue, defaultValue,
setPrinstineValue, setPrinstineValue,
@ -62,16 +55,13 @@ export default class DateControl extends React.PureComponent<
} = this.props; } = this.props;
if (defaultValue && value === defaultValue) { if (defaultValue && value === defaultValue) {
setPrinstineValue( const date = filterDate(defaultValue, data, format);
filterDate(defaultValue, data, format, utc).format(format) setPrinstineValue((utc ? moment.utc(date) : date).format(format));
);
} }
this.setState({ this.setState({
minDate: minDate ? filterDate(minDate, data, format, utc) : undefined, minDate: minDate ? filterDate(minDate, data, format) : undefined,
maxDate: maxDate ? filterDate(maxDate, data, format, utc) : undefined, maxDate: maxDate ? filterDate(maxDate, data, format) : undefined
minTime: minTime ? filterDate(minTime, data, timeFormat, utc) : undefined,
maxTime: maxTime ? filterDate(maxTime, data, timeFormat, utc) : undefined
}); });
} }
@ -79,8 +69,13 @@ export default class DateControl extends React.PureComponent<
const props = this.props; const props = this.props;
if (props.defaultValue !== nextProps.defaultValue) { if (props.defaultValue !== nextProps.defaultValue) {
const date = filterDate(
nextProps.defaultValue,
nextProps.data,
nextProps.format
);
nextProps.setPrinstineValue( nextProps.setPrinstineValue(
filterDate(nextProps.defaultValue, nextProps.data) (nextProps.utc ? moment.utc(date) : date).format(nextProps.format)
); );
} }
@ -89,23 +84,12 @@ export default class DateControl extends React.PureComponent<
props.maxDate !== nextProps.maxDate || props.maxDate !== nextProps.maxDate ||
props.data !== nextProps.data props.data !== nextProps.data
) { ) {
const utc = nextProps.utc;
this.setState({ this.setState({
minDate: nextProps.minDate minDate: nextProps.minDate
? filterDate( ? filterDate(nextProps.minDate, nextProps.data, this.props.format)
nextProps.minDate,
nextProps.data,
this.props.format,
utc
)
: undefined, : undefined,
maxDate: nextProps.maxDate maxDate: nextProps.maxDate
? filterDate( ? filterDate(nextProps.maxDate, nextProps.data, this.props.format)
nextProps.maxDate,
nextProps.data,
this.props.format,
utc
)
: undefined : undefined
}); });
} }

View File

@ -36,11 +36,11 @@ export default class DateRangeControl extends React.Component<
constructor(props: DateRangeProps) { constructor(props: DateRangeProps) {
super(props); super(props);
const {minDate, maxDate, data} = props; const {minDate, maxDate, data, format} = props;
this.state = { this.state = {
minDate: minDate ? filterDate(minDate, data) : undefined, minDate: minDate ? filterDate(minDate, data, format) : undefined,
maxDate: maxDate ? filterDate(maxDate, data) : undefined maxDate: maxDate ? filterDate(maxDate, data, format) : undefined
}; };
} }
@ -52,7 +52,8 @@ export default class DateRangeControl extends React.Component<
format, format,
data, data,
value, value,
joinValues joinValues,
utc
} = this.props; } = this.props;
if (defaultValue && value === defaultValue) { if (defaultValue && value === defaultValue) {
@ -63,19 +64,20 @@ export default class DateRangeControl extends React.Component<
setPrinstineValue( setPrinstineValue(
BaseDateRangePicker.formatValue( BaseDateRangePicker.formatValue(
{ {
startDate: filterDate(arr[0], data), startDate: filterDate(arr[0], data, format),
endDate: filterDate(arr[1], data) endDate: filterDate(arr[1], data, format)
}, },
format, format,
joinValues, joinValues,
delimiter delimiter,
utc
) )
); );
} }
} }
componentWillReceiveProps(nextProps: DateRangeProps) { componentWillReceiveProps(nextProps: DateRangeProps) {
const {data, minDate, maxDate} = nextProps; const {data, minDate, maxDate, format} = nextProps;
const props = this.props; const props = this.props;
if ( if (
@ -84,8 +86,8 @@ export default class DateRangeControl extends React.Component<
props.data !== data props.data !== data
) { ) {
this.setState({ this.setState({
minDate: minDate ? filterDate(minDate, data) : undefined, minDate: minDate ? filterDate(minDate, data, format) : undefined,
maxDate: maxDate ? filterDate(maxDate, data) : undefined maxDate: maxDate ? filterDate(maxDate, data, format) : undefined
}); });
} }
} }
@ -94,10 +96,11 @@ export default class DateRangeControl extends React.Component<
const { const {
defaultValue, defaultValue,
delimiter, delimiter,
format,
joinValues, joinValues,
setPrinstineValue, setPrinstineValue,
data data,
utc,
format
} = this.props; } = this.props;
if (prevProps.defaultValue !== defaultValue) { if (prevProps.defaultValue !== defaultValue) {
@ -110,12 +113,13 @@ export default class DateRangeControl extends React.Component<
arr arr
? BaseDateRangePicker.formatValue( ? BaseDateRangePicker.formatValue(
{ {
startDate: filterDate(arr[0], data), startDate: filterDate(arr[0], data, format),
endDate: filterDate(arr[1], data) endDate: filterDate(arr[1], data, format)
}, },
format, format,
joinValues, joinValues,
delimiter delimiter,
utc
) )
: undefined : undefined
); );

View File

@ -83,9 +83,11 @@ export const relativeValueRe = /^(.+)?(\+|-)(\d+)(minute|min|hour|day|week|month
export const filterDate = ( export const filterDate = (
value: string, value: string,
data: object = {}, data: object = {},
format = 'X' format = 'X',
utc: boolean = false
): moment.Moment => { ): moment.Moment => {
let m; let m,
mm = utc ? moment.utc : moment;
if (typeof value === 'string') { if (typeof value === 'string') {
value = value.trim(); value = value.trim();
@ -97,8 +99,8 @@ export const filterDate = (
const date = new Date(); const date = new Date();
const step = parseInt(m[3], 10); const step = parseInt(m[3], 10);
const from = m[1] const from = m[1]
? filterDate(m[1], data, format) ? filterDate(m[1], data, format, utc)
: moment( : mm(
/(minute|min|hour|second)s?/.test(m[4]) /(minute|min|hour|second)s?/.test(m[4])
? [ ? [
date.getFullYear(), date.getFullYear(),
@ -116,12 +118,12 @@ export const filterDate = (
: from.add(step, timeUnitMap[m[4]] as moment.DurationInputArg2); : from.add(step, timeUnitMap[m[4]] as moment.DurationInputArg2);
// return from[m[2] === '-' ? 'subtract' : 'add'](step, mapping[m[4]] || m[4]); // return from[m[2] === '-' ? 'subtract' : 'add'](step, mapping[m[4]] || m[4]);
} else if (value === 'now') { } else if (value === 'now') {
return moment(); return mm();
} else if (value === 'today') { } else if (value === 'today') {
const date = new Date(); const date = new Date();
return moment([date.getFullYear(), date.getMonth(), date.getDate()]); return mm([date.getFullYear(), date.getMonth(), date.getDate()]);
} else { } else {
return moment(value, format); return mm(value, format);
} }
}; };