question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not sure how getDateStr prop is supposed to work.

See original GitHub issue

Here is what the documentation says about getDateStr:

A function to override how to format the date into a String for display, receives a Date instance

Can someone explain me the following behavior?

This works:

<DatePicker
  ...
  format="LL"
/>

This doesn’t work (isn’t getDateStr supposed to replace format?):

<DatePicker
  ...
  getDateStr={rawDate => moment(rawDate).format('LL')}
/>

This works (and I can save rawDate for something else):

<DatePicker
  ...
  format="LL"
  getDateStr={rawDate => moment(rawDate).format('LL')}
/>

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

5reactions
willswinsoncommented, Jul 22, 2018

Same here. Makes no sense. It seems to suggest that you can work with values in the format property and override getDateStr to only change the text displayed in the field.

But, in the getDateStr, if you return a format different than the one specified in “format” property, it gives “Invalid Date”.

So…what’s the point?

3reactions
LucasGarcezcommented, Jan 26, 2020

The documentation is really not very clear. In my case the format I want to use for display is 'DD/ MM/YYYY HH:mm' so I return an object of typemoment()with this format in all places where I manipulate my date and do not use the DatePicker format props:

My initial state to date:

const initalDate = moment(new Date(),'DD/MM/YYYY HH:mm');
this.state = {date: initalDate}

In getDateStr I use the same format:

getDateStr={(date) => {
    const formatDate = moment(date).format('DD/MM/YYYY HH:mm')
    return formatDate;
 }}

So on onDateChange I change my state with a moment() object with the same format :

onDateChange={(date) => {
    let dateMoment = moment(date, 'DD/MM/YYYY HH:mm');
    //So my state continues with an object of type moment();
    this.setState({ date: dateMoment });
 }}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why You Should Check Your Prop Regularly - YouTube
Miles "Sonar" Burghoff explains how to quickly change a bass boat prop and why you should regularly check it to keep your motor...
Read more >
Boat Propeller Pitch Explained - How To Select the Right Prop
2022 Best Live Bait Rigs → https://bit.ly/jujurigsCAST NETS WE USE → https://bit.ly/2X9EJJjJoin us today in beautiful Biscayne Bay as we ...
Read more >
Five Reasons You May Need to Change Your Prop - BoatUS
Choosing the wrong prop or using a damaged prop can cause your boat to perform poorly, increasing fuel consumption or damage your engine...
Read more >
Extracting month from DS3231 function rtc.getDateStr()
Hello, Does anyone know if it is possible to extract only the month of the year from ... There is no getDateStr() function...
Read more >
How to Find the Right Boat Propeller | West Marine
Four-blade designs work well with boats that are difficult to get on plane, underpowered or used in watersports where top-end speed is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found