Add dates for #4575, fiddle with comments for #4578

This commit is contained in:
James Cole
2021-04-02 06:59:55 +02:00
parent 5750087d37
commit 00b0ce6c6e
9 changed files with 108 additions and 53 deletions

View File

@@ -127,7 +127,73 @@ export default {
this.setEnd(end);
this.range.start = start;
this.range.end = end;
this.generatePeriods()
return false;
},
generatePeriods: function () {
this.periods = [];
// create periods.
let today;
let end;
today = new Date(this.range.start);
// previous month
firstDayOfMonth = new Date(today.getFullYear(), today.getMonth()-1, 1);
lastDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 0);
this.periods.push(
{
start: firstDayOfMonth.toDateString(),
end: lastDayOfMonth.toDateString(),
title: new Intl.DateTimeFormat(this.locale, {year: 'numeric', month: 'long'}).format(firstDayOfMonth)
}
);
// this month
firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
lastDayOfMonth = new Date(today.getFullYear(), today.getMonth()+1, 0);
this.periods.push(
{
start: firstDayOfMonth.toDateString(),
end: lastDayOfMonth.toDateString(),
title: new Intl.DateTimeFormat(this.locale, {year: 'numeric', month: 'long'}).format(firstDayOfMonth)
}
);
// next month
let firstDayOfMonth = new Date(today.getFullYear(), today.getMonth()+1, 1);
let lastDayOfMonth = new Date(today.getFullYear(), today.getMonth()+2, 0);
this.periods.push(
{
start: firstDayOfMonth.toDateString(),
end: lastDayOfMonth.toDateString(),
title: new Intl.DateTimeFormat(this.locale, {year: 'numeric', month: 'long'}).format(firstDayOfMonth)
}
);
// last 7 days
today = new Date;
end = new Date;
end.setDate(end.getDate() - 7);
this.periods.push(
{
start: end.toDateString(),
end: today.toDateString(),
title: this.$t('firefly.last_seven_days')
}
);
// last 30 days:
end.setDate(end.getDate() - 23);
this.periods.push(
{
start: end.toDateString(),
end: today.toDateString(),
title: this.$t('firefly.last_thirty_days')
}
);
// last 30 days
// everything
}
},
computed: {
@@ -149,31 +215,8 @@ export default {
}
this.range.start = new Date(this.start);
this.range.end = new Date(this.end);
this.periods = [];
// create periods.
// last 7 days
let today = new Date;
let end = new Date;
end.setDate(end.getDate() - 7);
this.periods.push(
{
start: end.toDateString(),
end: today.toDateString(),
title: this.$t('firefly.last_seven_days')
}
);
this.generatePeriods();
// last 30 days:
end.setDate(end.getDate() - 23);
this.periods.push(
{
start: end.toDateString(),
end: today.toDateString(),
title: this.$t('firefly.last_thirty_days')
}
);
// last 30 days
// everything
},
range: function (value) {
//console.log('User updated range');

View File

@@ -92,13 +92,18 @@ export default {
},
timeStr: {
get() {
// console.log('getTimeStr: ' + this.localTime);
if (this.localTime instanceof Date && !isNaN(this.localTime)) {
return ('0' + this.localTime.getHours()).slice(-2) + ':' + ('0' + this.localTime.getMinutes()).slice(-2) + ':' + ('0' + this.localTime.getSeconds()).slice(-2);
let localStr = ('0' + this.localTime.getHours()).slice(-2) + ':' + ('0' + this.localTime.getMinutes()).slice(-2) + ':' + ('0' + this.localTime.getSeconds()).slice(-2);
// console.log('Time is: ' + localStr);
return localStr;
}
return '';
},
set(value) {
// console.log('Set: ' + value);
if ('' === value) {
// console.log('Value is empty, set 00:00:00');
this.localTime.setHours(0);
this.localTime.setMinutes(0);
this.localTime.setSeconds(0);
@@ -108,9 +113,11 @@ export default {
// bit of a hack but meh.
let current = new Date(this.localTime.getTime());
let parts = value.split(':');
current.setHours(parseInt(parts[0]));
current.setMinutes(parseInt(parts[1]));
current.setSeconds(parseInt(parts[2]));
// console.log('Parts are:');
// console.log(parts);
current.setHours(parseInt(parts[0] ?? 0));
current.setMinutes(parseInt(parts[1] ?? 0));
current.setSeconds(parseInt(parts[2] ?? 0));
this.localTime = current;
this.$emit('set-time', {time: this.localTime});
}