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

Allow passing of a datetimeCreator prop to the DatetimePicker component #2000

Closed
zedrdave opened this issue Nov 19, 2019 · 2 comments
Closed

Comments

@zedrdave
Copy link
Contributor

As described in #1083, there is a dateCreator prop available to change the Date creator on the DatePicker component (and for example, allow to set a timezone different from the user locale).

It would be great if the same prop was available for DatetimePicker (and maybe even TimePicker?). At the moment, there seems to be an (undocumented) DatetimeCreator prop, but I don't think it behaves as expected (it never seems to get called when using the component with a set value).

@zedrdave
Copy link
Contributor Author

@jtommy Thanks a lot for the quick response!

Actually, after looking a bit more, I think more code would need to be changed: in order to be able to support a different timezone, we would need to be able to use the custom creator with existing values as well (lines 46 and 286 of TimepickerMixin.js)…

@zedrdave
Copy link
Contributor Author

Hello again…

After looking closer at the code, I believe it would make more sense to support timezones by providing a tzOffset value (in minutes) that is added/subtracted when converting between value, computedValue and selectedValue… So that selectedValue is in the desired timezone, but the component value is still UTC.

Code changes would be something like:

    data() {
        return {
            dateSelected:  new Date(this.value.getTime() + this.tzOffset * 60000),
[...]
    computed: {
        computedValue: {
            get() {
                return new Date(this.dateSelected.getTime() + this.tzOffset * 60000)
            },
            set(value) {
                this.dateSelected = new Date(value.getTime() + this.tzOffset * 60000)
                this.$emit('input', this.dateSelected)
            }
        },

In order to properly handle other props such as minTime, maxTime and unselectableTimes, it would probably be necessary to either add the offset there too. Maybe by creating computed values hoursSelectedOffset etc?

What do you think?

If that seems like the right track, I'll be happy to provide a pull request.

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

No branches or pull requests

1 participant