Skip to content

Commit

Permalink
Revert "Feat: Add date type (elastic#271)" (elastic#281)
Browse files Browse the repository at this point in the history
This reverts commit 070a48ae2148a6d4ded1b66276068e6480cdd346.
  • Loading branch information
w33ble authored Jan 8, 2018
1 parent fb5a717 commit 0c66a04
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 67 deletions.
33 changes: 7 additions & 26 deletions common/functions/date.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,25 @@
import moment from 'moment';

const getInputDate = (input) => {
// return current date if no input
if (!input) return new Date();

// attempt to cast to a number
const numInput = Number(input);
if (!isNaN(numInput)) return numInput;

// return the input
return input;
};

export const date = {
name: 'date',
type: 'date',
type: 'number',
context: {
types: ['null'],
},
help: 'Returns the current time, or a time parsed from a string, as milliseconds since epoch.',
help: 'Returns the current time, or a time parsed from a string, as milliseconds since epoch',
args: {
_: {
types: ['string', 'null'],
help: 'An optional date string to parse into milliseconds since epoch. ' +
'Can be either a valid Javascript Date input or a string to parse using the format argument. ',
help: 'An optional date string to parse into milliseconds since epoch',
},
format: {
types: ['string', 'null'],
help: 'The momentJS format for parsing the optional date string (See https://momentjs.com/docs/#/displaying/).',
help: 'The momentJS format for parsing the optional date string (See https://momentjs.com/docs/#/displaying/)',
},
},
fn: (context, args) => {
const inputDate = getInputDate(args._);
const outputDate = (args._ && args.format) ? moment(inputDate, args.format).toDate() : new Date(inputDate);

if (isNaN(outputDate.getTime())) throw new Error(`Invalid date input: ${args._}`);

return {
type: 'date',
value: outputDate,
};
if (!args._) return moment().valueOf();
if (!args.format) return moment(args._).valueOf();
return moment(args._, args.format).valueOf();
},
};
2 changes: 1 addition & 1 deletion common/functions/formatdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const formatdate = {
},
},
fn: (context, args) => {
return moment(new Date(context)).format(args._);
return moment(context).format(args._);
},
};
38 changes: 0 additions & 38 deletions common/types/date.js

This file was deleted.

2 changes: 0 additions & 2 deletions common/types/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { boolean } from './boolean';
import { datatable } from './datatable';
import { dataurl } from './dataurl';
import { date } from './date';
import { error } from './error';
import { filter } from './filter';
import { image } from './image';
Expand All @@ -17,7 +16,6 @@ export const typeSpecs = [
boolean,
datatable,
dataurl,
date,
error,
filter,
image,
Expand Down

0 comments on commit 0c66a04

Please sign in to comment.