-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
create SimpleDate and CalendarLocale objects #2839
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the datepicker issue w/ a comment saying that work is happening on the datepicker
branch?
import {Injectable} from '@angular/core'; | ||
|
||
|
||
const SUPPORTS_INTL_API = !!(new Date().toLocaleDateString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safari 9 has toLocaleDateString
but not the full Intl
API.
Here's the check that modernizr uses:
https://github.com/Modernizr/Modernizr/blob/master/feature-detects/intl.js
} | ||
|
||
protected createArray<T>(length: number, valueFunction: (index: number) => T): T[] { | ||
return Array.apply(null, Array(length)).map((v: undefined, i: number) => valueFunction(i)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just Array(length).map(...)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently that just creates an object like {length: 7}
without adding keys for the indices, which causes map
to not work.
date.toNativeDate().toLocaleDateString(undefined, {year: 'numeric'}) : String(date.year); | ||
} | ||
|
||
protected createArray<T>(length: number, valueFunction: (index: number) => T): T[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is classically called range
. Rename to that and move it outside the class as just a module function?
|
||
protected createDaysArray(format: string) { | ||
return this.createArray(7, | ||
i => new Date(2017, 0, i + 1).toLocaleDateString(undefined, {weekday: format})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to MDN:
When formatting large numbers of dates, it is better to create an Intl.DateTimeFormat object and use the function provided by its format property.
Not sure if this counts as a "large number", but it wouldn't hurt to make the formatter
} | ||
|
||
|
||
export class DefaultCalendarLocale implements CalendarLocale { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add class description
|
||
|
||
@Injectable() | ||
export abstract class CalendarLocale { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add class description
|
||
it('lists dates', () => { | ||
expect(calendarLocale.dates).toEqual([ | ||
null, '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this start with null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a comment in the base class, basically I thought it would be nice to not have to do calendarLocale.dates[date + 1]
all the time (especially since months and days are 0-indexed), so I added null
as the representation for dates[0]
import {SimpleDate} from './simple-date'; | ||
|
||
|
||
describe('DefaultCalendarLocale', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests don't seem to well-capture using the current locale with fallback behavior. Any ideas on how to improve this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately I don't think there's any way to set the browser's locale from JS
@@ -0,0 +1,11 @@ | |||
export class SimpleDate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add class description
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
CLAs look good, thanks! |
+ @andrewseguin since kara is busy caretaking this week |
} | ||
|
||
private _createFormatFunction( | ||
options: Object, fallback: (date: SimpleDate) => string): (date: SimpleDate) => string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix identations
return range(31, i => dtf.format(new Date(2017, 0, i + 1))); | ||
} | ||
|
||
private _createFormatFunction( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave a description of this function? It's especially difficult to visually parse the signature of the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, also simplified it since its just as easy to return null and specify the fallback elsewhere
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
* create SimpleDate and CalendarLocale objects * tests * addressed comments * make parseDate more robust * simplify createFormatFunction
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.