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

v-model to accept ISO datetimes #804

Closed
IlyaSemenov opened this issue Apr 3, 2024 · 3 comments
Closed

v-model to accept ISO datetimes #804

IlyaSemenov opened this issue Apr 3, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@IlyaSemenov
Copy link

Is your feature request related to a problem? Please describe.
Typically, external APIs send and receive dates in ISO datetime format. I'm always frustrated that I need to add cumbersome watch/computed/type conversion boilerplate to convert between ISO datetime and the formats the date picker supports (native Date or timestamp or date-fns tokens).

Describe the solution you'd like
I'd like model-type to support new option: iso.

Describe alternatives you've considered
For dates (not date+time+timezone) I could use model-type="yyyy-MM-dd". However, it doesn't seem possible to construct the full ISO8601 datetime string as T seems to be a reserved token in date-fns formatter that you're using. Also, this kind of manual format templating is prone to mistakes/typos.

@IlyaSemenov IlyaSemenov added awaiting triage The issue is not reviewed by the maintainers enhancement New feature or request labels Apr 3, 2024
@Jasenkoo
Copy link
Contributor

Jasenkoo commented Apr 3, 2024

The ISO string can be natively parsed with new Date(), meaning you just pass the date string as it is to the datepicker. When you move it from the v-model just use .toISOString()

You can also use T , just need to wrap it in quotes, 'T'

@Jasenkoo Jasenkoo closed this as completed Apr 3, 2024
@Jasenkoo Jasenkoo added wontfix This will not be worked on and removed awaiting triage The issue is not reviewed by the maintainers enhancement New feature or request labels Apr 3, 2024
@IlyaSemenov
Copy link
Author

That's basically what I was referring to: boilerplate conversion.

Instead of doing:

<vue-date-picker v-model="fields.startTime" model-type="iso" />

one has to repeat this for each field:

<vue-date-picker
  :model-value="fields.startTime"
  @update:model-value="v => fields.startTime = v?.toISOString()"
/>

I'm not really following why timestamps have first class support and ISO time, arguably much more popular format, doesn't deserve one. 🤔

@Jasenkoo
Copy link
Contributor

Jasenkoo commented Apr 4, 2024

You are right, I'll add it, it is a minor thing to implement.

@Jasenkoo Jasenkoo reopened this Apr 4, 2024
@Jasenkoo Jasenkoo added enhancement New feature or request and removed wontfix This will not be worked on labels Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants