forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Feat: Add date type (elastic#271)" (elastic#281)
This reverts commit 070a48ae2148a6d4ded1b66276068e6480cdd346.
- Loading branch information
Showing
4 changed files
with
8 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters