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

reflector(moment): remove the dependency of moment #761

Closed
vthinkxie opened this issue Dec 15, 2017 · 2 comments
Closed

reflector(moment): remove the dependency of moment #761

vthinkxie opened this issue Dec 15, 2017 · 2 comments

Comments

@vthinkxie
Copy link
Member

What problem does this feature solve?

reduce the package size since angular has provided all the locales we need

What does the proposed API look like?

may bring some break changes.

@trotyl
Copy link
Contributor

trotyl commented Dec 15, 2017

Draft design doc for anyone works on this

Background

Angular has dropped dependency of Intl API and uses self-provided locale data extracted from CLDR starts from v5.

Usage

An Angular application needs to define which locale to support by registering the locale data, like:

import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
import localeZh from '@angular/common/locales/zh';

// the second parameter 'fr', 'zh' are optional
registerLocaleData(localeFr, 'fr');
registerLocaleData(localeFr, 'zh');

More details can be found in Angular i18n doc.

All registered locale data would be available in runtime. Then the application needs to provide the LOCALE_ID somehow, for example by CLI option at build time or using navigator.language at runtime. (Or whatever methods like url path, that's not decided by library)

But the library should provide an option to override LOCALE_ID as the DI result cannot be changed after setup. (Which can be a separate work)

Implementation

For template formatting, just use the DatePipe, it will automatically use the locale provided by LOCALE_ID token, also there is a locale parameter to override it.

For logic formatting, Angular would provide something like LocaleService in 5.2 or 5.3, but before that (being our minimal requirement), we need to make it work for current infrastructure. The easiest way to do is the pipe as a service pattern (should use pipe directly when possible), like:

@NgModule({
  providers: [ DatePipe ]
})
class LocaleModule { }

@Injectable()
class LocaleService {
  constructor(private datePipe: DatePipe) { }

  formatDate(date: Date, format: string, locale: string): string {
    return this.datePipe.transform(date, format, /* timezone */ undefined, locale);
  }
}

For other utilities like plus one day, can be achieved by some tiny 3rd-party libraries like date-fns. But could still have some problem for typing in CommonJS module integration. (Should only import the exact helpers for size consideration)

@lock
Copy link

lock bot commented May 15, 2019

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 15, 2019
hsuanxyz pushed a commit to hsuanxyz/ng-zorro-antd that referenced this issue Aug 5, 2020
…ker against to ant-design (NG-ZORRO#1254)

close NG-ZORRO#1367 close NG-ZORRO#1267 close NG-ZORRO#1107 close NG-ZORRO#1097 close NG-ZORRO#1094 close NG-ZORRO#1079 close NG-ZORRO#1063 close NG-ZORRO#1060 close NG-ZORRO#1060 close NG-ZORRO#1046 close NG-ZORRO#1034 close NG-ZORRO#955 close NG-ZORRO#906 close NG-ZORRO#761 close NG-ZORRO#707 close NG-ZORRO#741 close NG-ZORRO#646 
* refactor(module:date-picker): TODO: complete all

complete more

complete date wrapper, need more flexiable with APIs of value select and change

complete parts of footer

the datepicker almost complete

commit to avoid side-effects with experiments

import the legacy timepicker, date-picker almost done

complete the common apis for datepicker

support all API for date-picker (which related to timepicker needs tebe complete)

split the date picker into more flexable components, pending for next range-picker

combine range-popup into date-popup, need self-testing

plug out the common abstract picker for both single/range picker

the range picker is almost done, but lots of work need todo still

soft remove legacy time-picker

compat with the latest time-picker

re-render the content of picker when open

add month-picker, need tobe done

done with month-picker & ready to develop week-picker

add support of week-picker

support ngModel for all pickers

complete parts of demos

support timePickerDisabled && timePickerDisabled (need testing)

support time-picker for date/range picker and more options like disabledDate/disabledTime

complete all demo and the chinese doc

add some testings for date-picker component

add more testing for date-picker component

fix problems of overlay's origin and backdrop with open

add testing for date-picker with ngModel

done testings for date-picker, start to add testings for range-picker

add testings for range picker

increase coverage of testings for date picker module

add testings for month-picker

increase more testing coverage

complete more testings for date picker module

* trimming relates for build packaging

* complete the zh/en documents

* support animations when hide/show

* fix(module:date-picker): change default to ngModel

* fix(module:date-picker): change default to ngModel

* fix the range's wrong default value setting

* make CandyDate changes into range picker testing

* aim to trigger ci

test(module:date-picker): fix month-picker test
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants