zhaoyongjie commented on a change in pull request #11418:
URL: 
https://github.com/apache/incubator-superset/pull/11418#discussion_r545154054



##########
File path: 
superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterControl.tsx
##########
@@ -0,0 +1,872 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import React, { useState, useEffect } from 'react';
+import rison from 'rison';
+import moment, { Moment } from 'moment';
+import {
+  SupersetClient,
+  styled,
+  supersetTheme,
+  t,
+  TimeRangeEndpoints,
+} from '@superset-ui/core';
+import {
+  buildTimeRangeString,
+  formatTimeRange,
+  SEPARATOR,
+} from 'src/explore/dateFilterUtils';
+import { getClientErrorObject } from 'src/utils/getClientErrorObject';
+import Button from 'src/components/Button';
+import ControlHeader from 'src/explore/components/ControlHeader';
+import Label from 'src/components/Label';
+import Modal from 'src/common/components/Modal';
+import {
+  Col,
+  DatePicker,
+  Divider,
+  Input,
+  InputNumber,
+  Radio,
+  Row,
+} from 'src/common/components';
+import Icon from 'src/components/Icon';
+import { Select } from 'src/components/Select';
+import {
+  TimeRangeFrameType,
+  CommonRangeType,
+  CalendarRangeType,
+  CustomRangeType,
+  CustomRangeDecodeType,
+  CustomRangeKey,
+  PreviousCalendarWeek,
+  PreviousCalendarMonth,
+  PreviousCalendarYear,
+} from './types';
+import {
+  COMMON_RANGE_OPTIONS,
+  CALENDAR_RANGE_OPTIONS,
+  RANGE_FRAME_OPTIONS,
+  SINCE_GRAIN_OPTIONS,
+  UNTIL_GRAIN_OPTIONS,
+  SINCE_MODE_OPTIONS,
+  UNTIL_MODE_OPTIONS,
+} from './constants';
+
+const MOMENT_FORMAT = 'YYYY-MM-DD[T]HH:mm:ss';
+const DEFAULT_SINCE = moment()
+  .utc()
+  .startOf('day')
+  .subtract(7, 'days')
+  .format(MOMENT_FORMAT);
+const DEFAULT_UNTIL = moment().utc().startOf('day').format(MOMENT_FORMAT);
+
+const customTimeRangeDecode = (timeRange: string): CustomRangeDecodeType => {
+  const splitDateRange = timeRange.split(SEPARATOR);
+  const DATETIME_CONSTANT = ['now', 'today'];
+  const defaultCustomRange: CustomRangeType = {
+    sinceDatetime: DEFAULT_SINCE,
+    sinceMode: 'relative',
+    sinceGrain: 'day',
+    sinceGrainValue: -7,
+    untilDatetime: DEFAULT_UNTIL,
+    untilMode: 'specific',
+    untilGrain: 'day',
+    untilGrainValue: 7,
+    anchorMode: 'now',
+    anchorValue: 'now',
+  };
+
+  /**
+   * RegExp to test a string for a full ISO 8601 Date
+   * Does not do any sort of date validation, only checks if the string is 
according to the ISO 8601 spec.
+   *  YYYY-MM-DDThh:mm:ss
+   *  YYYY-MM-DDThh:mm:ssTZD
+   *  YYYY-MM-DDThh:mm:ss.sTZD
+   * @see: https://www.w3.org/TR/NOTE-datetime
+   */
+  const iso8601 = 
String.raw`\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:(?:[+-]\d\d:\d\d)|Z)?`;
+  const datetimeConstant = String.raw`TODAY|NOW`;
+  const grainValue = String.raw`[+-]?[1-9][0-9]*`;
+  const grain = String.raw`YEAR|QUARTER|MONTH|WEEK|DAY|HOUR|MINUTE|SECOND`;
+  const CUSTOM_RANGE_EXPRESSION = RegExp(
+    
String.raw`^DATEADD\(DATETIME\("(${iso8601}|${datetimeConstant})"\),\s(${grainValue}),\s(${grain})\)$`,
+    'i',
+  );
+  const ISO8601_AND_CONSTANT = RegExp(
+    String.raw`^${iso8601}$|^${datetimeConstant}$`,
+    'i',
+  );
+
+  if (splitDateRange.length === 2) {
+    const [since, until] = [...splitDateRange];
+
+    // specific : specific
+    if (
+      since.match(ISO8601_AND_CONSTANT) &&

Review comment:
       Thank you very much for the reminder! So useful tips!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to