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

create SimpleDate and CalendarLocale objects #2839

Merged
merged 5 commits into from
Feb 2, 2017

Conversation

mmalerba
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jan 27, 2017
@jelbourn
Copy link
Member

FYI @pkozlowski-opensource

Copy link
Member

@jelbourn jelbourn left a 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);
Copy link
Member

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));
Copy link
Member

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(...) ?

Copy link
Contributor Author

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[] {
Copy link
Member

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}));
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

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',
Copy link
Member

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?

Copy link
Contributor Author

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', () => {
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add class description

@googlebot
Copy link

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 cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels Feb 1, 2017
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Feb 1, 2017
@mmalerba
Copy link
Contributor Author

mmalerba commented Feb 1, 2017

+ @andrewseguin since kara is busy caretaking this week

}

private _createFormatFunction(
options: Object, fallback: (date: SimpleDate) => string): (date: SimpleDate) => string {
Copy link
Contributor

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(
Copy link
Contributor

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

Copy link
Contributor Author

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

@andrewseguin andrewseguin added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Feb 1, 2017
@mmalerba mmalerba removed the action: merge The PR is ready for merge by the caretaker label Feb 2, 2017
@mmalerba mmalerba merged commit c2eb2a8 into angular:datepicker Feb 2, 2017
mmalerba added a commit to mmalerba/components that referenced this pull request Feb 9, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit that referenced this pull request Feb 9, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit that referenced this pull request Feb 27, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit that referenced this pull request Mar 2, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit to mmalerba/components that referenced this pull request Mar 6, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit that referenced this pull request Mar 17, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit to mmalerba/components that referenced this pull request Mar 28, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit that referenced this pull request Apr 14, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit that referenced this pull request Apr 20, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit that referenced this pull request Apr 29, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit that referenced this pull request May 5, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
mmalerba added a commit that referenced this pull request May 9, 2017
* create SimpleDate and CalendarLocale objects

* tests

* addressed comments

* make parseDate more robust

* simplify createFormatFunction
@mmalerba mmalerba deleted the dp-init branch April 3, 2018 15:15
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants