diff --git a/src/addons/calendar/pages/edit-event/edit-event.html b/src/addons/calendar/pages/edit-event/edit-event.html
index d6c49a422..32b691c6e 100644
--- a/src/addons/calendar/pages/edit-event/edit-event.html
+++ b/src/addons/calendar/pages/edit-event/edit-event.html
@@ -32,7 +32,8 @@
{{ 'core.date' | translate }}
-
+
@@ -165,9 +166,10 @@
{{ 'addon.calendar.durationuntil' | translate }}
-
+ [displayFormat]="dateFormat" [disabled]="form.controls.duration.value != 1">
+
diff --git a/src/addons/calendar/pages/edit-event/edit-event.page.ts b/src/addons/calendar/pages/edit-event/edit-event.page.ts
index bcb25057c..5d826a466 100644
--- a/src/addons/calendar/pages/edit-event/edit-event.page.ts
+++ b/src/addons/calendar/pages/edit-event/edit-event.page.ts
@@ -75,6 +75,8 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
eventRepeatId?: number;
otherEventsCount = 0;
eventId?: number;
+ maxDate: string;
+ minDate: string;
// Form variables.
form: FormGroup;
@@ -94,7 +96,6 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
protected fb: FormBuilder,
@Optional() protected svComponent: CoreSplitViewComponent,
) {
-
this.currentSite = CoreSites.getCurrentSite()!;
this.errors = {
required: Translate.instant('core.required'),
@@ -122,6 +123,9 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
this.form.addControl('repeat', this.fb.control(false));
this.form.addControl('repeats', this.fb.control('1'));
this.form.addControl('repeateditall', this.fb.control(1));
+
+ this.maxDate = CoreTimeUtils.getDatetimeDefaultMax();
+ this.minDate = CoreTimeUtils.getDatetimeDefaultMin();
}
/**
diff --git a/src/addons/mod/data/fields/date/component/addon-mod-data-field-date.html b/src/addons/mod/data/fields/date/component/addon-mod-data-field-date.html
index 4d1c12b81..f6bcd38db 100644
--- a/src/addons/mod/data/fields/date/component/addon-mod-data-field-date.html
+++ b/src/addons/mod/data/fields/date/component/addon-mod-data-field-date.html
@@ -1,7 +1,8 @@
-
+
+
diff --git a/src/addons/mod/data/fields/date/component/date.ts b/src/addons/mod/data/fields/date/component/date.ts
index fcf20c918..5639572e9 100644
--- a/src/addons/mod/data/fields/date/component/date.ts
+++ b/src/addons/mod/data/fields/date/component/date.ts
@@ -28,6 +28,8 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo
format!: string;
displayDate?: number;
+ maxDate?: string;
+ minDate?: string;
/**
* @inheritdoc
@@ -43,6 +45,8 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo
this.format = CoreTimeUtils.fixFormatForDatetime(CoreTimeUtils.convertPHPToMoment(
Translate.instant('core.strftimedate'),
));
+ this.maxDate = CoreTimeUtils.getDatetimeDefaultMax();
+ this.minDate = CoreTimeUtils.getDatetimeDefaultMin();
if (this.searchMode) {
this.addControl('f_' + this.field.id + '_z');
diff --git a/src/addons/userprofilefield/datetime/component/datetime.ts b/src/addons/userprofilefield/datetime/component/datetime.ts
index 8f350740c..d494cf549 100644
--- a/src/addons/userprofilefield/datetime/component/datetime.ts
+++ b/src/addons/userprofilefield/datetime/component/datetime.ts
@@ -33,8 +33,8 @@ import { CoreLang } from '@services/lang';
export class AddonUserProfileFieldDatetimeComponent extends CoreUserProfileFieldBaseComponent {
format?: string;
- min?: number;
- max?: number;
+ min?: string;
+ max?: string;
valueNumber = 0;
monthNames?: string[];
@@ -66,20 +66,17 @@ export class AddonUserProfileFieldDatetimeComponent extends CoreUserProfileField
));
// Check min value.
- if (field.param1) {
- const year = parseInt(field.param1, 10);
- if (year) {
- this.min = year;
- }
+ if (field.param1 && Number(field.param1)) {
+ this.min = field.param1;
}
// Check max value.
- if (field.param2) {
- const year = parseInt(field.param2, 10);
- if (year) {
- this.max = year;
- }
+ if (field.param2 && Number(field.param2)) {
+ this.max = field.param2;
}
+
+ this.max = this.max || CoreTimeUtils.getDatetimeDefaultMin();
+ this.max = this.max || CoreTimeUtils.getDatetimeDefaultMax();
}
/**
diff --git a/src/core/services/utils/time.ts b/src/core/services/utils/time.ts
index 7439be193..c9202cb72 100644
--- a/src/core/services/utils/time.ts
+++ b/src/core/services/utils/time.ts
@@ -367,6 +367,20 @@ export class CoreTimeUtilsProvider {
}
}
+ /**
+ * Get the default max year for datetime inputs.
+ */
+ getDatetimeDefaultMax(): string {
+ return String(moment().year() + 20);
+ }
+
+ /**
+ * Get the default min year for datetime inputs.
+ */
+ getDatetimeDefaultMin(): string {
+ return String(moment().year() - 20);
+ }
+
}
export const CoreTimeUtils = makeSingleton(CoreTimeUtilsProvider);