Skip to content

Conversation

nutritiousreject
Copy link
Contributor

@nutritiousreject nutritiousreject commented Jan 13, 2020

Added support for manually specifying the date format on thhe

Please read and mark the following check list before creating a pull request:

Short description of what this resolves:

Previously date formats were hard-coded into the DD-MM-YYYY format, which is a huge PITA if you're an american who uses backwards ass date formats.

You can now specify what format you would like your date to display in by passing the dateFormat property into the component as follows

<Datepicker date={this.state.date} onSelect={(date) => {this.selectDate(date)}} dateFormat='MM-DD-YYYY' />

I've built the project and ran it myself to confirm it works.

Closes #815

manually specifying localization string
@artyorsh
Copy link
Collaborator

Thanks for opening a PR! I like the idea, but I guess it's better to do this with fecha, which is included as a dependency to perform date operations in this library. I will investigate this feature and use your PR for this. Contributions are welcome 👐

@nutritiousreject
Copy link
Contributor Author

I'll see if I can integrate fetcha into the string localization when i'm at work today and push another commit to the PR. Usually its slow as heck

@nutritiousreject
Copy link
Contributor Author

nutritiousreject commented Jan 13, 2020

Just want to make sure i'm not missing anything.

this.props.dateService.format(date, dateFormat)

Which gets defined in

 static defaultProps: Partial<BaseDatepickerProps> = {
    dateService: new NativeDateService(),

And the date service gets imported from
import { NativeDateService } from '../calendar/service/nativeDate.service';

And the format function being called in nativeDate.service.ts in my change is


  public format(date: Date, format: string): string {
    return fecha.format(date, format);
  }

So no changes should be necessary? The only difference is allowing users to specify the string instead of hardcoding it as a const. Fecha was already doing the string localization to begin with, just with a hardcoded date format

@artyorsh
Copy link
Collaborator

@nutritiousreject yes. You may need to call format here. Same for Range Datepicker

@artyorsh artyorsh requested a review from 32penkin January 17, 2020 15:37
@artyorsh artyorsh merged commit 705dc97 into akveo:master Jan 21, 2020
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.

Enable string localization on DatePicker

4 participants