techouse / intl-date-time

International DateTime for Laravel Nova
MIT License
57 stars 21 forks source link

Possibility to define userTimezone for specific field #43

Closed eAvio closed 3 years ago

eAvio commented 3 years ago

Thank you for the great package.

We how ever found one exception in our use case, where we would need to set different Timezone for one specific field.

Although our global Nova.config.userTimezone is set to "sl" we have one specific field where user needs to enter time in UTC.

Inspecting index.vue we found out that it is imposible to set userTimezone for specific field only:

userTimezone: () => Nova.config.userTimezone || moment.tz.guess(),

What we suggest is to change userTimezone to:

userTimezone()
            {
                if (this.field.userTimeZone) {
                    return this.field.userTimeZone
                }

                return Nova.config.userTimezone || moment.tz.guess();
            },

Then we can use "withMeta" on specific field: DateTime::make('Date to', 'date_to')->withTimeShort()->locale(config('app.date_locale'))->timeFormat('HH:mm')->withMeta(['userTimeZone' => 'UTC']),

We also noticed that "timezone" is sometimes written as "timeZone" and sometimes as "timezone" maybe it would be good idea to unify that.

techouse commented 3 years ago

Hey,

Good suggestions, however, lately I've really had little time to work on any of my pet projects and I would greatly appreciate it if you made a pull request with all your suggestions.

Cheers!

techouse commented 3 years ago

Merged and released in v1.6.3