Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support date and datetime data type #21

Open
techniq opened this issue Jul 25, 2018 · 1 comment
Open

Support date and datetime data type #21

techniq opened this issue Jul 25, 2018 · 1 comment

Comments

@techniq
Copy link
Owner

techniq commented Jul 25, 2018

Extracted from #20 (comment)

Regarding dates and times they do not appear to qualify the values with a type except optionally with a duration.

DateValue eq 2012-12-03
DateTimeOffsetValue eq 2012-12-03T07:16:23Z
DurationValue eq duration'P12DT23H59M59.999999999999S'
DurationValue eq 'P12DT23H59M59.999999999999S'
TimeOfDayValue eq 07:59:59.999

We could support the following in handleValue

  • { type: 'datetimeoffset', value: date } and a Date instance (like we do now):
    • date.toISOString() => 2012-12-03T07:16:23Z
  • { type: 'date', value: date }:
    • date.toISOString().split('T')[0] => 2012-12-03

We should also support date as either a Date instance or a string (ex. 2018-01-02):

const dateValue = (typeof date === 'string') ? new Date(date) : date instanceof Date ? date : null
const value = dateValue && dateValue.toISOString();
@samuelportz
Copy link
Contributor

I think it would be nice also to accept integer, when a type is given.

let dateValue = null;
switch (typeof value) {
    case 'string':
    case 'number':
        dateValue = new Date(value).toISOString();
        break;
    case 'object':
        if (value instanceof Date) dateValue = value.toISOString();
        break;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants