This project is a sandbox to play with Angular and Nx, to improve my coding standards and release some open source stuff.
Reactive Datasource for Angular.
A fork of the official datepicker module with time picking support.
Open Source Angular Libraries: MatDataSource, MatDatepicker
Home Page: http://matheo.co/demos/
License: MIT License
It would be nice to have among datepicker types quarter
Hi,
Good work
I wanted to know if I could add the option of seconds in the time, currently the format that has is H:MM, could I add the seconds too?h:mm:ss
Thanks
When adding both MatDatepickerModule and MatNativeDateModule to my EventsModule, a runtime error occurs.
More than one custom value accessor matches form control with unspecified name attribute
See screenshots.
To work like before MatNativeDateModule moved to /core.
Angular Version:
Angular CLI: 12.0.3
Node: 14.17.0
Package Manager: npm 7.16.0
OS: win32 x64
Anything else relevant?
Datepicker version: 11.2.15
The picker is not changing first day of week depending on locale like original picker does.
Could be luxon-related, since ngx-material-luxon has a specific configuration for the first day of the week
Stackblitz gives ngcc error atm unfortunately.
There's an example of french locale here:
https://material.angular.io/components/datepicker/examples
(lu = monday)
@matheo/datepicker:
Should change the first day of the week depending on locale.
Alternatively with configuration like
Angular Version:
@angular/core: ^11.2.9,
@matheo/[email protected]
Issue on macOS both chrome and safari
When I tried to update both matheo datepicker and luxon to the latest, I got an error and I could not update luxon to the latest
Package "@matheo/datepicker" has an incompatible peer dependency to "luxon" (requires "^1.28.0", would install "2.3.0")
Package "@matheo/datepicker" has an incompatible peer dependency to "luxon" (requires "^1.28.0", would install "2.3.0").
matheo datepicker should support the latest major update of luxon as peer dependency
First of all, good job with the datetimer picker component!
Is there any way to use it with:
https://www.npmjs.com/package/ngx-material-luxon
Which is pretty much plug-n-play with the original matdatepicker?
Angular Material allows multiple parse formats but the adapter only considers singular string values for the parseFormat
.
Thought I'd mention it in case that's something that could be supported by the package internally, but was able to get around the issue by monkey patching in polyfills.ts
DateFnsAdapter.prototype.parse = function (
value: any,
parseFormat: string | string[]
): Date | null {
if (value) {
if (typeof value === 'string') {
const parseFormats = Array.isArray(parseFormat)
? parseFormat
: [parseFormat];
const _value = value.trim();
for (let format of parseFormats) {
const d = parse(_value, format, new Date(), {
locale: this._dateFnsLocale,
});
if (d && d.toString() !== 'Invalid Date') {
return this.options.useUtc ? zonedTimeToUtc(d, 'UTC') : d;
}
}
return new Date(value);
}
if (typeof value === 'number') {
return toDate(value);
}
if (value instanceof Date) {
return this.clone(value as Date);
}
return value;
}
return value;
};
Firstly, thank you for creating this library specifically for the date-time picker implementation; it is surprising that Angular material hasn't addressed this after 4 years of requests! Your implementation feels right at home alongside other material components and works beautifully :)
One aspect which I feel makes use of the library difficult however is the lack of emitted Date
values whenever the user is navigating through views. Specifically take the following typical flow:
new Date()
-> Mon May 09 2022 12:34:56)matDatepickerApply
directive)I would expect to be able to access a Date
object which contains the currently highlighted date emitted each time the user makes a selection (steps 2, 3 and 4) and ideally is initialised with the value that the datepicker displays when opened (step 1). To my knowledge there is no way to access this value using the APIs provided. This means in practice that I have no way of knowing what the user has selected until step 5 at which point Tue May 10 2022 17:30:00 is correctly emitted via (dateChange)
.
There are concrete drawbacks to not having this information being made available, mainly in providing a unified user experience within the component and in other related components. For example:
min
/max
validation (related downstream issue: https://github.com/matheo/angular/issues/47)The ideal implementation would expose the following APIs at minimum (arbitrary names) in much the same way that the dateChange interface works:
@Output() dateSelect: EventEmitter<Date | null>
dateSelected: Date | null
Note: The first image demonstrates the scenario in which it would be beneficial to disable the 'Select' button as the currently highlighted date is clearly out of valid range. The button would be reenabled on highlighting a valid date, as in the second image
Please let me know your thoughts and thanks again for the library!
I've imported the datepicker library into my Angular 13 project, as per the instructions and am receiving the following build error:
Error: node_modules/@matheo/datepicker/lib/date-range-input.d.ts:22:22 - error TS2720: Class 'MatDateRangeInput<D>' incorrectly implements class 'MatFormFieldControl<DateRange<D>>'. Did you mean to extend 'MatFormFieldControl<DateRange<D>>' and inherit its members as a subclass?
Property 'ngModel' is missing in type 'MatDateRangeInput<D>' but required in type 'MatFormFieldControl<DateRange<D>>'.
22 export declare class MatDateRangeInput<D> implements MatFormFieldControl<DateRange<D>>, MatDatepickerControl<D>, MatDateRangeInputParent<D>, MatDateRangePickerInput<D>, AfterContentInit, OnChanges, OnDestroy {
~~~~~~~~~~~~~~~~~
node_modules/@angular/material/form-field/form-field-control.d.ts:14:5
14 ngModel: T | null;
~~~~~~~
'ngModel' is declared here.
✖ Failed to compile.
I have checked the declaration for abstract class MatFormFieldControl and confirmed that it does indeed declare ngModel as an input.
My angular imports are all v13 (including material), as shown in the package.json excerpt below:
"dependencies": {
"@angular/animations": "^13.0.2",
"@angular/cdk": "^13.0.2",
"@angular/common": "^13.0.2",
"@angular/compiler": "^13.0.2",
"@angular/core": "^13.0.2",
"@angular/flex-layout": "^13.0.0-beta.38",
"@angular/forms": "^13.0.2",
"@angular/localize": "^13.0.2",
"@angular/material": "^13.0.2",
"@angular/platform-browser": "^13.0.2",
"@angular/platform-browser-dynamic": "^13.0.2",
"@angular/router": "^13.0.2",
"@angular/service-worker": "^13.0.2",
...
"@matheo/datepicker": "^13.0.0-beta.1",
...
}
Any advice would be greatly appreciated!
I'm using matheo Luxon Date Adapter for my app. I am using Luxon in my entire app. I had to copy the code from the source code and swapped out with unofficial Google LuxonDateAdapeter. I realized that Google version and Matheo version is almost identical except Matheo version has conversion for time for obvious reason. However, I found one more difference which is not related to time. getDayOfWeek is modified to negate 1 from luxon default weekday. The default if Sunday returns 7, Matheo version return 6. When I got the code from Google, I also got unit test to go with it too. Then now I swapped with Matheo version, this getDayOfWeek unit test is failing. To fix this unit test, I can just remove negation of 1 but is there a specific reason why Matheo version is negating 1?
Find the Google version LuxonAdapter from this link
https://github.com/andreialecu/ngx-material-luxon/blob/main/projects/ngx-material-luxon/src/lib/adapter/luxon-date-adapter.ts
And Find Unit Test for the Google Version LuxonDateAdapter from this link
https://github.com/andreialecu/ngx-material-luxon/blob/main/projects/ngx-material-luxon/src/lib/adapter/luxon-date-adapter.spec.ts
Use Matheo Verion LuxonDateAdapeter and run the unit tests
All test should still pass.
Angular Version:
Angular CLI: 12.0.4
Node: 14.17.4
Package Manager: npm 7.17.0
OS: win32 x64
Angular: 12.0.4
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, platform-browser-dynamic
... router, service-worker
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1200.4
@angular-devkit/build-angular 12.0.4
@angular-devkit/core 12.0.4
@angular-devkit/schematics 12.0.4
@angular/flex-layout 12.0.0-beta.34
@schematics/angular 12.0.4
ng-packagr 12.0.5
rxjs 6.6.6
Hi, DatePicker currently doesn't work with Angular 13. I tried to create a PR to fix it but looks like I need your help to finish it.
#44
Is there an example of how to format the datetime within the input?
In the Angular Material examples they reference @angular/material-moment-adapter
, but this doesn't know anything about your newly introduced fields.
So I'm wondering if someone ever tried, for instance, to format it as 2021-03-27 17:35
?
I followed the docs on how to install and use it, but when I try to serve the application I get this error:
ERROR in ./node_modules/@matheo/datepicker/fesm2015/matheo-datepicker.js 3344:27-44
"export 'coerceStringArray' was not found in '@angular/cdk/coercion'
npm install @matheo/datepicker
import { MatDatepickerModule } from '@matheo/datepicker';
import { MatNativeDateModule } from '@matheo/datepicker/core';@NgModule({
imports: [
MatNativeDateModule,
MatDatepickerModule,
...
],
...
})
export class AppModule {}
<input matInput [matDatepicker]="picker"/>
<mat-datepicker-toggle matSuffix [for]="picker">
<mat-datepicker type="datetime" #picker>
The app is served without errors and the component works.
9.1.13
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 9.1.15
Node: 14.17.0
OS: win32 x64
Angular: 9.1.13
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.901.15
@angular-devkit/build-angular 0.901.15
@angular-devkit/build-optimizer 0.901.15
@angular-devkit/build-webpack 0.901.15
@angular-devkit/core 9.1.15
@angular-devkit/schematics 9.1.15
@angular/cdk 9.2.4
@angular/cli 9.1.15
@angular/material 9.2.4
@ngtools/webpack 9.1.15
@schematics/angular 9.1.15
@schematics/update 0.901.15
rxjs 6.5.5
typescript 3.8.3
webpack 4.42.0
I am a big fan of @coachcare/datepicker. The new package improved a lot. It should be better if it can support touch and drag for Time picker (even Date picker) to precise selection for mobile device. Thank you.
Angular Material Datepicker Multi-year view has 24 years in the table.
Hopefully want to set the yearsPerPage dynamically as well.
<mat-datepicker #picker [yearsPerPage]="N">
Can we set this value via API?
<mat-datepicker #picker [yearsPerPage]="N">
We can set date range dynamically using MAT_DATE_RANGE_SELECTION_STRATEGY
/** Injection token used to customize the date range selection behavior. */
export const MAT_DATE_RANGE_SELECTION_STRATEGY =
new InjectionToken('MAT_DATE_RANGE_SELECTION_STRATEGY');
DatePicker for TimeView when type="time"
In the class MatCalendarHeader
in updateValues()
the formatting for the hour is ignoring the double digit: it doesn't display the 0
in front of the hour!
this._hourButtonText = hours.toString();
--> any hour < 10 has only 1 digit
Hour button text should have 0 for hour < 10, example => 06 instead of 6.
Could you please fix it as you do for the minutes? like this:
this._hourButtonText = ('00' + hours).slice(-2);
Maybe I am expecting too much from this very nice lib but.
When I'm selecting a time 13:27:45
, the value of the form update to a full date like 2021-06-14T13:27:45.099Z
The form should update the value with 13:27:45
Angular Version:
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1200.3
@angular-devkit/build-angular 12.0.3
@angular-devkit/core 12.0.3
@angular-devkit/schematics 12.0.3
@angular/cdk 12.0.4
@angular/material 12.0.4
@schematics/angular 12.0.3
rxjs 6.6.7
typescript 4.2.4
When using dynamic values for the type property, then the display override does not work.
For example, if I use the picker like this:
<mat-datepicker type="{{dateType}}" #picker>
<mat-datepicker [type]="dateType" #picker>
Then the picker will give you the right input, but then the display is always shown as date, instead of time or datetime.
Being able to use variables as input type
Anything else relevant?
As a background, I am using the MAT_DATE_FORMATS to make the display show date and also time. It works great when I use the datepicker as type='datetime' (direct strintg) but for some reason it does not like variables. I cannot understand where ths issue is.
As a workaround, if I use several ngIf it works perfectly. Maybe this is just something related to angular and the providers and something else I am missing. Like I said, a workaround exists but it should not be necessary I guess.
This works:
<mat-form-field *ngIf="dateType == 'datetime'" appearance="fill">
<mat-label>{{title}}</mat-label>
<input matInput [matDatepicker]="picker" [formControl]="fg.get(fieldName)" [min]="minDate" [max]="maxDate"/>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker type="datetime" #picker>
<mat-datepicker-actions>
<button mat-button matDatepickerCancel>Cancel</button>
<button mat-raised-button matDatepickerApply>Apply</button>
</mat-datepicker-actions>
</mat-datepicker>
</mat-form-field>
<mat-form-field *ngIf="dateType == 'date'" appearance="fill">
<mat-label>{{title}}</mat-label>
<input matInput [matDatepicker]="picker" [formControl]="fg.get(fieldName)" [min]="minDate" [max]="maxDate"/>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker type="date" #picker>
<mat-datepicker-actions>
<button mat-button matDatepickerCancel>Cancel</button>
<button mat-raised-button matDatepickerApply>Apply</button>
</mat-datepicker-actions>
</mat-datepicker>
</mat-form-field>
<mat-form-field *ngIf="dateType == 'time'" appearance="fill">
<mat-label>{{title}}</mat-label>
<input matInput [matDatepicker]="picker" [formControl]="fg.get(fieldName)" [min]="minDate" [max]="maxDate"/>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker type="time" #picker>
<mat-datepicker-actions>
<button mat-button matDatepickerCancel>Cancel</button>
<button mat-raised-button matDatepickerApply>Apply</button>
</mat-datepicker-actions>
</mat-datepicker>
</mat-form-field>
The date time picker edits hours and minutes no seconds, however it doesn't 0 seconds, looks like its the current system seconds at time of edit.
Seconds returned as 0
Angular 12.1
Using custom Dayjs DateAdaptor
When I use my custom theming then threre is a warning in build:
WARNING: The same color styles are generated multiple times. Read more about how style duplication can be avoided in a dedicated guide. https://github.com/angular/components/blob/master/guides/duplicate-theming-styles.md node_modules\@angular\material\core\theming\_theming.scss 312:7 private-check-duplicate-theme-styles() node_modules\@matheo\datepicker\_theming.scss 360:3 mat-datepicker-theme() src\@shs\scss\theme.scss 10:5 shs-core-theme() src\app\scss\themes\_light.theme.scss 121:5 @use src\app\scss\app.theme.scss 5:1 @use src\styles.scss 5:1 root stylesheet
WARNING: The same color styles are generated multiple times. Read more about how style duplication can be avoided in a dedicated guide. https://github.com/angular/components/blob/master/guides/duplicate-theming-styles.md node_modules\@angular\material\core\theming\_theming.scss 312:7 private-check-duplicate-theme-styles() node_modules\@matheo\datepicker\_theming.scss 360:3 mat-datepicker-theme() src\@shs\scss\theme.scss 10:5 shs-core-theme() src\app\scss\themes\_light.theme.scss 136:9 @use src\app\scss\app.theme.scss 5:1 @use src\styles.scss 5:1 root stylesheet
WARNING: The same color styles are generated multiple times. Read more about how style duplication can be avoided in a dedicated guide. https://github.com/angular/components/blob/master/guides/duplicate-theming-styles.md node_modules\@angular\material\core\theming\_theming.scss 312:7 private-check-duplicate-theme-styles() node_modules\@matheo\datepicker\_theming.scss 360:3 mat-datepicker-theme() src\@shs\scss\theme.scss 10:5 shs-core-theme() src\app\scss\themes\_dark.theme.scss 116:5 @use src\app\scss\app.theme.scss 6:1 @use src\styles.scss 5:1 root stylesheet
I have more themes in the application and I call "@include datePickerTheming.mat-datepicker-theme($theme)" for every theme the same way like for other components. This datepicker gives me the error during ng serve.
No build warnings.
Manually inputting dates doesn't consider locale
Steps to reproduce the behavior:
It should respect current locale (in this case "en-GB")
I wish I had more information on this, I'm still working through a suitable solution.
After upgrading from Angular 14 to 15, and still using the "Legacy" API for all Material related things, the only issue I've noticed is that any Material based component used by this library is not getting any style applied to it. It works and looks fine in development, but after building the production build and deploying, the styles are just not there/very ugly.
Start with an Angular 14 application, implement Angular Material + this library, then run the upgrades to angular 15. I believe the way the @include datepicker.theme($theme); is working is causing the library to use the "new" API rather than the legacy API.
It's possible I just need to bite the bullet and upgrade to the "new" Material MDC API. But it would be nice to have an option to provide a legacy theme builder to this library.
I would expect the styles to look the same between dev and production.
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 15.0.4
Node: 16.13.0
Package Manager: npm 8.1.0
OS: win32 x64
Angular: 15.0.4
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
... service-worker
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1500.4
@angular-devkit/build-angular 15.0.4
@angular-devkit/core 15.0.4
@angular-devkit/schematics 15.0.4
@angular/cdk 15.0.3
@angular/material 15.0.3
@schematics/angular 15.0.4
rxjs 6.6.7
typescript 4.8.4
When a day is selected in the datetime picker and a min date is specified, an invalid date can easily be selected by switching months & pressing the apply button.
A date before the minimum date should not be selectable.
Suggestion for stackblitz for new issues:
https://stackblitz.com/edit/components-issue-gkdfcp?file=package.json
Forked from https://stackblitz.com/fork/components-issue
(official material / angular issues)
For some reason the mat-calendar component doesn't get the mat-calendar class applied - any ideas why? Messes up the width!
The content of the date range picker is overflowing on the bottom, if a month has 6 rows of days or 6 weeks, so to speak. This happens in May 2021, January 2021, August 2020, etc.
DATE RANGE
picker on the bottom rightA clear and concise description of what you expected to happen.
Angular Version: v11.2.14 (Angular version used on http://matheo.co/demos/datepicker)
Anything else relevant?
if (unit === 'hour') {
// Prevent office hours from being selected.
return hour >= 6 && hour <= 19;
}
But the hour 5 looks clickable (opacity = 1) and 19 has opacity while should be full black.
Opacity of the hours should respect the condition the filter is returning.
The click on hours and minutes should be ignored and remains in the same view.
Hi
I am trying to apply a different format to the datetime (MAT_DATE_FORMATS) but I can't get it to work.
For example, if we use the Material example but use the imports from your library, the date format doesn't work.
https://stackblitz.com/angular/nkdkbolbgvg?file=src%2Fapp%2Fdatepicker-formats-example.ts
// import { MatDatepickerModule } from '@angular/material/datepicker'
// import { MatNativeDateModule } from '@angular/material/core'
import { MatDatepickerModule } from '@matheo/datepicker'
import { MatNativeDateModule } from '@matheo/datepicker/core'
Can you add an example?
thanks
cdk/coersion was created on version 11, so for ealier versions it's missing this dependency.
Any version previous to 11
Angular Version:
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 10.2.2
Node: 13.14.0
OS: win32 x64
Angular: 10.2.4
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1002.2
@angular-devkit/build-angular 0.1002.2
@angular-devkit/core 10.2.2
@angular-devkit/schematics 10.2.2
@angular/cdk 10.2.7
@angular/cli 10.2.2
@angular/material 10.2.7
@schematics/angular 10.2.2
@schematics/update 0.1002.2
rxjs 6.6.3
typescript 4.0.7
Thanks for this library.
I may not fully understand the meaning of optional streams as it is not well documented. However, I would expect the first data request to be initiated without waiting for an optional stream to emit. Right now it seems that the optional streams must emit some value before the first data request will occur.
Adding the following operator to connect()
in datasource-stream.ts
does make the data source work as I would expect it to.
before
optional.length
? merge(...optional).pipe(scan(this.reducePartials, {} as Partial<T>))
: of({} as Partial<T>),
after
optional.length
? merge(...optional).pipe(
startWith({}),
scan(this.reducePartials, {} as Partial<T>),
)
: of({} as Partial<T>),
I don't have a fully reproducible example right now but I can create one at some point if it will help.
A simple data source with the following stream added
this.addStream({
name: 'filter',
stream: form.valueChanges,
optional: true,
});
The data source should automatically process the first data request.
If applicable, add screenshots to help explain your problem.
Angular Version:
Anything else relevant?
Hello matheo,
is this a timePicker bug or have I made any mistake?
core.js:6150 ERROR TypeError: Cannot read property 'getUnit' of undefined
at dateInputsHaveChanged (matheo-datepicker.js:4560)
at MatDatepickerInput.ngOnChanges (matheo-datepicker.js:4393)
at MatDatepickerInput.rememberChangeHistoryAndInvokeOnChangesHook (core.js:1506)
at callHook (core.js:2525)
at callHooks (core.js:2492)
at executeCheckHooks (core.js:2424)
at selectIndexInternal (core.js:8383)
at Module.ɵɵadvance (core.js:8372)
at JourneySearchComponent_Template (journey-search.component.html:36)
at executeTemplate (core.js:9538)
<mat-form-field appearance='standard'>
<mat-label>Uhrzeit</mat-label>
<input matInput [matDatepicker]='this.timePicker' formControlName='time'>
<mat-datepicker touchUi #timePicker type='time' [twelveHour]='false'></mat-datepicker>
<mat-error>Bitte wähle eine korrekte Uhrzeit aus</mat-error>
</mat-form-field>
this.apiTokenForm = this.formBuilder.group({
departureTravelPoint: [null, [Validators.required, TravelPointValidators.pointFormat]],
arrivalTravelPoint: [null, [Validators.required, TravelPointValidators.pointFormat]],
date: [new Date(), Validators.required],
time: [new Date(), Validators.required],
isArrivalDateTime: [false]
}, {
updateOn: 'submit'
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.