feat(date/timepicker): Enhance DateAdapter to accept diffetent types for date and time
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 35/100
- Type d'issue
- Fonctionnalité
- Clarté
- À clarifier
- Activité
- Calme
- Stack technique
- angular, typescript
- Domaine
- frontend
Piste de recherche
Commencez par suivre l’API DateAdapter jusqu’aux points d’entrée de date picker et time picker. Comparez les hypothèses actuelles partagées concernant la date et l’heure avec les types de date et d’heure séparés demandés, la gestion des valeurs invalides et le comportement de addSeconds/setTime. Le travail est considéré comme terminé lorsqu’un design d’API rétrocompatible et un plan d’implémentation prennent en charge LocalDate/PlainDate avec LocalTime/PlainTime sans casts non sûrs.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Feature Description
Currently DateAdapter is designed to work with instances of the same time for date and time, this is how JavaScript Date works and many other replacement libraries do too. Many libraries have noticed this is not always desirable. Java got the external Joda-Time library that became the model for the modern java.time replacement. On the JavaScript side I use js-joda, a port of the original Java Joda-Time library
Much like the new Temporal API, these libraries have aditional split representations of a date and a time, LocalDate and LocalTime and LocalDateTime when you need both without a timezone attached to it.
The Temporal API, brings these kind of types to JavaScript with PlainDate, PlainTime and PlainDateTime (better naming than the Local prefix).
DateAdapter is not designed to have a date picker with a LocalDate/PlainDate and a time picker with a LocalTime/PlainTime. Yes you can make it work but it requires a few hacks, for example the time parts on my js-joda adapter.
isDateInstance(obj: unknown): boolean {
return obj instanceof LocalDate || obj instanceof LocalTime;
}
isValid(date: LocalDate): boolean {
return date !== INVALID_VALUE;
}
invalid(): LocalDate {
return INVALID_VALUE;
}
override compareDate(first: LocalDate, second: LocalDate): number {
return first.compareTo(second);
}
override sameDate(first: LocalDate | null, second: LocalDate | null): boolean {
if (first != null && second != null) {
// WORKAROUND to allow generating the list of times in the time picker
if (first instanceof LocalTime && second instanceof LocalTime) {
return true;
}
return first.equals(second);
}
return (first ?? null) === (second ?? null);
}
override setTime(_target: LocalDate, hours: number, minutes: number, seconds: number): LocalDate {
return LocalTime.of(hours, minutes, seconds) as unknown as LocalDate;
}
override getHours(date: LocalDate): number {
return (date as unknown as LocalTime).hour();
}
override getMinutes(date: LocalDate): number {
return (date as unknown as LocalTime).minute();
}
override getSeconds(date: LocalDate): number {
return (date as unknown as LocalTime).second();
}
override addSeconds(date: LocalDate, amount: number): LocalDate {
const time = date as unknown as LocalTime;
const remainingSeconds = SECONDS_PER_DAY - time.toSecondOfDay();
if (remainingSeconds < amount) {
return INVALID_VALUE;
}
return time.plusSeconds(amount) as unknown as LocalDate;
}
Notice there is a lot of unsafe casting because the subclass extends DateAdapter<LocalDate>, it will have less casting if it was DateAdapter<LocalDate | LocalTime> but that would need more type checks on methods exclusively used by the date picker.
The API changes required are resumed in:
- The adapter should be split in two or have a different type for the time. I prefer to split the adapter, because that way there could be multiple combinations of adapters for PlainDate, PlainTime, Instant (for date and for time pickers) in Temporal API for example.
- js-joda/Temporal API has no concept of an invalid Local/Plain object, their constructors throw exceptions, So I have to hack a fake date
INVALID_VALUEas an specific instance with a very big year, to use as an invalid value. So the logic that requires an invalid value should change, for example the time picker usesisValid()to stop the loop that builds the times to show. addSeconds()andsetTime()should not tie a time to date ever, if possible start with a start time.
Making these changes backward compatible will be a challenge, but I think it is needed to make usable the Temporal API Plain classes with the pickers.
Use Case
No response
- Langage dominant
- TypeScript
- Étoiles
- 25k
- Forks
- 6.8k
- Merge moyen
- 1 j 7 h
- PR mergées (30 j)
- 92
Préparer son environnement
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de angular/components
-
area: material/datepicker P4
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
angular/components#33763 · 2 commentaires · 3 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
area: material/table P4
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
angular/components#33709 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
area: material/table docs gemini-triaged P4
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
angular/components#33455 ·
Les mainteneurs répondent en général sous 1 jour
-
area: material/core gemini-triaged P3
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
angular/components#33059 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
area: material/dialog P2
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
angular/components#30536 · 3 réactions ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de angular/components
Issues similaires
-
module-request
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
-
ports get and web print 'Port N already in use, trying next...' for every busy port they skipOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
appandflow/stim#1604 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
lingdojo/kana-dojo#31060 · 1 commentaire · 5 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
SSH workspace restore rewrites relative symlinks into the deleted sync-back staging directoryOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
paperclipai/paperclip#14173 ·
Les mainteneurs répondent en général sous 1 jour
-
needs-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour