mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 15:30:13 +01:00
Merge pull request #3557 from lindhork/master
Added possibility to specify hours in single digits in 24 hour format
This commit is contained in:
commit
d6d40b35a5
2 changed files with 44 additions and 14 deletions
|
|
@ -1,3 +1,8 @@
|
||||||
|
// Helper function to replace HH with H for 24 hours format, because H allows also single-digit hours
|
||||||
|
function adjustedTimeFormat() {
|
||||||
|
return moment.localeData().longDateFormat('LT').replace(/HH/i, 'H');
|
||||||
|
}
|
||||||
|
|
||||||
// Edit received, start, due & end dates
|
// Edit received, start, due & end dates
|
||||||
BlazeComponent.extendComponent({
|
BlazeComponent.extendComponent({
|
||||||
template() {
|
template() {
|
||||||
|
|
@ -59,7 +64,7 @@ BlazeComponent.extendComponent({
|
||||||
},
|
},
|
||||||
'keyup .js-time-field'() {
|
'keyup .js-time-field'() {
|
||||||
// parse for localized time format in strict mode
|
// parse for localized time format in strict mode
|
||||||
const dateMoment = moment(this.find('#time').value, 'LT', true);
|
const dateMoment = moment(this.find('#time').value, adjustedTimeFormat(), true);
|
||||||
if (dateMoment.isValid()) {
|
if (dateMoment.isValid()) {
|
||||||
this.error.set('');
|
this.error.set('');
|
||||||
}
|
}
|
||||||
|
|
@ -71,16 +76,26 @@ BlazeComponent.extendComponent({
|
||||||
const time =
|
const time =
|
||||||
evt.target.time.value ||
|
evt.target.time.value ||
|
||||||
moment(new Date().setHours(12, 0, 0)).format('LT');
|
moment(new Date().setHours(12, 0, 0)).format('LT');
|
||||||
|
const newTime = moment(time, adjustedTimeFormat(), true);
|
||||||
|
const newDate = moment(evt.target.date.value, 'L', true);
|
||||||
const dateString = `${evt.target.date.value} ${time}`;
|
const dateString = `${evt.target.date.value} ${time}`;
|
||||||
const newDate = moment(dateString, 'L LT', true);
|
const newCompleteDate = moment(dateString, 'L ' + adjustedTimeFormat(), true);
|
||||||
if (newDate.isValid()) {
|
if (!newTime.isValid()) {
|
||||||
this._storeDate(newDate.toDate());
|
this.error.set('invalid-time');
|
||||||
Popup.close();
|
evt.target.time.focus();
|
||||||
} else {
|
}
|
||||||
|
if (!newDate.isValid()) {
|
||||||
this.error.set('invalid-date');
|
this.error.set('invalid-date');
|
||||||
evt.target.date.focus();
|
evt.target.date.focus();
|
||||||
}
|
}
|
||||||
|
if (newCompleteDate.isValid()) {
|
||||||
|
this._storeDate(newCompleteDate.toDate());
|
||||||
|
Popup.close();
|
||||||
|
} else {
|
||||||
|
if (!this.error){
|
||||||
|
this.error.set('invalid');
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'click .js-delete-date'(evt) {
|
'click .js-delete-date'(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
// Helper function to replace HH with H for 24 hours format, because H allows also single-digit hours
|
||||||
|
function adjustedTimeFormat() {
|
||||||
|
return moment.localeData().longDateFormat('LT').replace(/HH/i, 'H');
|
||||||
|
}
|
||||||
|
|
||||||
DatePicker = BlazeComponent.extendComponent({
|
DatePicker = BlazeComponent.extendComponent({
|
||||||
template() {
|
template() {
|
||||||
return 'datepicker';
|
return 'datepicker';
|
||||||
|
|
@ -77,7 +82,7 @@ DatePicker = BlazeComponent.extendComponent({
|
||||||
},
|
},
|
||||||
'keyup .js-time-field'() {
|
'keyup .js-time-field'() {
|
||||||
// parse for localized time format in strict mode
|
// parse for localized time format in strict mode
|
||||||
const dateMoment = moment(this.find('#time').value, 'LT', true);
|
const dateMoment = moment(this.find('#time').value, adjustedTimeFormat(), true);
|
||||||
if (dateMoment.isValid()) {
|
if (dateMoment.isValid()) {
|
||||||
this.error.set('');
|
this.error.set('');
|
||||||
}
|
}
|
||||||
|
|
@ -89,16 +94,26 @@ DatePicker = BlazeComponent.extendComponent({
|
||||||
const time =
|
const time =
|
||||||
evt.target.time.value ||
|
evt.target.time.value ||
|
||||||
moment(new Date().setHours(12, 0, 0)).format('LT');
|
moment(new Date().setHours(12, 0, 0)).format('LT');
|
||||||
|
const newTime = moment(time, adjustedTimeFormat(), true);
|
||||||
|
const newDate = moment(evt.target.date.value, 'L', true);
|
||||||
const dateString = `${evt.target.date.value} ${time}`;
|
const dateString = `${evt.target.date.value} ${time}`;
|
||||||
const newDate = moment(dateString, 'L LT', true);
|
const newCompleteDate = moment(dateString, 'L ' + adjustedTimeFormat(), true);
|
||||||
if (newDate.isValid()) {
|
if (!newTime.isValid()) {
|
||||||
this._storeDate(newDate.toDate());
|
this.error.set('invalid-time');
|
||||||
Popup.close();
|
evt.target.time.focus();
|
||||||
} else {
|
}
|
||||||
|
if (!newDate.isValid()) {
|
||||||
this.error.set('invalid-date');
|
this.error.set('invalid-date');
|
||||||
evt.target.date.focus();
|
evt.target.date.focus();
|
||||||
}
|
}
|
||||||
|
if (newCompleteDate.isValid()) {
|
||||||
|
this._storeDate(newCompleteDate.toDate());
|
||||||
|
Popup.close();
|
||||||
|
} else {
|
||||||
|
if (!this.error){
|
||||||
|
this.error.set('invalid');
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'click .js-delete-date'(evt) {
|
'click .js-delete-date'(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue