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

Add 'todayInstantiator' property to allow custom today's Date creation #1083

Merged
merged 3 commits into from Nov 14, 2018
Merged

Add 'todayInstantiator' property to allow custom today's Date creation #1083

merged 3 commits into from Nov 14, 2018

Conversation

jonagoldman
Copy link
Contributor

@jonagoldman jonagoldman commented Nov 13, 2018

Fixes #1080 by adding a new todayInstantiator property.

This allows to pass a function like this:

<b-datepicker :today-instantiator="todayInstantiator"></b-datepicker>
todayInstantiator() {
    return new Date()
},

This fixes some issues when the browser default new Date() instantiation used inside the component does not match the way each application works with dates.

For example, in an app that uses Moment or Luxon to set a timezone, the today's date set by the app can be different from the today's date used inside the component.

With this property I have the freedom to do something like this:

todayInstantiator() {
    return moment().tz('Australia/Sydney').toDate()
},

The todayInstantiator property is a function that must always return a regular JS Date object representing today's date.

Please note this function only applies when the component wants to get the today's date using new Date() and does not change anything else, ensuring that nothing breaks.

@codecov
Copy link

codecov bot commented Nov 13, 2018

Codecov Report

Merging #1083 into dev will increase coverage by 0.05%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff            @@
##             dev    #1083      +/-   ##
=========================================
+ Coverage   42.9%   42.95%   +0.05%     
=========================================
  Files         41       41              
  Lines       1296     1299       +3     
  Branches     403      404       +1     
=========================================
+ Hits         556      558       +2     
- Misses       721      722       +1     
  Partials      19       19
Impacted Files Coverage Δ
src/utils/config.js 100% <ø> (ø) ⬆️
src/components/datepicker/DatepickerTable.vue 24.13% <ø> (ø) ⬆️
src/components/datepicker/DatepickerTableRow.vue 31.57% <ø> (ø) ⬆️
src/components/datepicker/Datepicker.vue 37.5% <60%> (+1.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25c2a24...e43d892. Read the comment docs.

@jtommy
Copy link
Member

jtommy commented Nov 14, 2018

@jonagoldman PR is ok, but i'm not sure about the prop name to be honest

@jonagoldman
Copy link
Contributor Author

jonagoldman commented Nov 14, 2018

@jtommy I'm not sure either :) First I called it date-instatiator but it's not accureate as it only instantiates today's date. Maybe today-creator, today-date or date-creator ?

@jtommy
Copy link
Member

jtommy commented Nov 14, 2018

today-date or date-creator, as you want

@jonagoldman
Copy link
Contributor Author

@jtommy done

@jtommy
Copy link
Member

jtommy commented Nov 14, 2018

@jonagoldman Thanks

@jtommy jtommy merged commit 6c0009b into buefy:dev Nov 14, 2018
@zedrdave
Copy link
Contributor

zedrdave commented Nov 19, 2019

If I understand correctly, this would allow displaying the Datepicker in an arbitrary timezone instead of the user local by default?

Would it be possible to add the same parameter to Timepicker, so that it can be available to all components (I'm assuming it would then be possible to use Datetimepicker by providing both parameters to the subcomponents, right?)…

Sorry, please ignore previous paragraph: I hadn't realise the name had been changed to dateCreator and that there was indeed already a datetimeCreator in DatetimePicker!

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

Successfully merging this pull request may close these issues.

Datepicker: Allow to pass property for custom Date object creation
3 participants