nextcloud / calendar

📆 Calendar app for Nextcloud
https://apps.nextcloud.com/apps/calendar
GNU Affero General Public License v3.0
966 stars 236 forks source link

Incorrect relative day on dashboard #4892

Closed jokabrink closed 7 months ago

jokabrink commented 1 year ago

Steps to reproduce

  1. Create a date for the whole day (i.e. 20.01.2023)
  2. Go to the dashboard and count the number of days to the specified date

Expected behavior

The difference of calendar days. So when the current date shows 12.01.2023 21:42, the appointment should show in 8 days.

Actual behaviour

An approximate rounding of days depending on the current time. So a date on 20.01.2023 is sometimes in 8 days, sometimes in 7.

The reason appears to be the following. Execute this via node with @nextcloud/moment installed:

const moment = require("moment");
//import moment from '@nextcloud/moment'
a = moment("2023-01-12 21:42");
date_1 = moment("2023-01-20 00:00");
date_2 = moment("2023-01-20 09:00");
date_3 = moment("2023-01-20 10:00");
console.log(date_1.from(a));
console.log(date_2.from(a));
console.log(date_3.from(a));

Output:

in 7 days
in 7 days
in 8 days

The moment package introduces an approximate rounding. Possible solution is to change https://github.com/nextcloud/calendar/blob/main/src/views/Dashboard.vue#L241 accordingly. An idea would be to add another case like nextMonth with using t('calendar', '[in %n days]') instead of relying on moment.

Also, I believe this .replace('replace-from-now', moment(event.start).locale(locale) in https://github.com/nextcloud/calendar/blob/main/src/views/Dashboard.vue#L256 could be moved to https://github.com/nextcloud/calendar/blob/main/src/views/Dashboard.vue#L255.

Calendar app version

4.1.1

CalDAV-clients used

Web App

Browser

No response

Client operating system

No response

Server operating system

No response

Web server

None

Database engine version

None

PHP engine version

None

Nextcloud version

No response

Updated from an older installed version or fresh install

Updated from an older version

List of activated apps

No response

Nextcloud configuration

No response

Web server error log

No response

Log file

No response

Browser log

No response

Additional info

No response

jokabrink commented 1 year ago

I had a bit more time to dig into this. The possible above fixes are garbage, I didn't quite know the API and JS.

But now I think I got a fix. The problem and solution is described in this SO post. Cut short, the time part needs to be set to 00:00 for proper day differences. This could be done via .from(moment().startOf('day')) instead of .fromNow(). The fix is a one liner at https://github.com/nextcloud/calendar/blob/main/src/views/Dashboard.vue#L256.

miaulalala commented 1 year ago

I had a bit more time to dig into this. The possible above fixes are garbage, I didn't quite know the API and JS.

But now I think I got a fix. The problem and solution is described in this SO post. Cut short, the time part needs to be set to 00:00 for proper day differences. This could be done via .from(moment().startOf('day')) instead of .fromNow(). The fix is a one liner at https://github.com/nextcloud/calendar/blob/main/src/views/Dashboard.vue#L256.

wanna open a PR with your oneliner? Happy to approve!

jokabrink commented 7 months ago

The issue appears to be fixed.