Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

49779 Fix date conversion with negative time zone in my-spent-time widget

Christophe Bliard3b20568377cd
diff --git a/frontend/src/app/features/calendar/op-calendar.service.ts b/frontend/src/app/features/calendar/op-calendar.service.ts
index 490f456139f..a9f58521b61 100644
--- a/frontend/src/app/features/calendar/op-calendar.service.ts
+++ b/frontend/src/app/features/calendar/op-calendar.service.ts
@@ -35,8 +35,9 @@ export class OpCalendarService extends UntilDestroyedMixin {
}
applyNonWorkingDay({ date }:{ date?:Date }, nonWorkingDays:IDay[]):string[] {
- const formatted = moment(date).format('YYYY-MM-DD');
- if (date && (this.weekdayService.isNonWorkingDay(date) || nonWorkingDays.find((el) => el.date === formatted))) {
+ const utcDate = moment(date).utc();
+ const formatted = utcDate.format('YYYY-MM-DD');
+ if (date && (this.weekdayService.isNonWorkingDay(utcDate) || nonWorkingDays.find((el) => el.date === formatted))) {
return ['fc-non-working-day'];
}
return [];
diff --git a/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts b/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts
index 6ea5a477926..89ddff84c6a 100644
--- a/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts
+++ b/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts
@@ -123,7 +123,7 @@ export class TimeEntryCalendarComponent {
public scaleRatio = 1;
- protected memoizedTimeEntries:{ start:Date, end:Date, entries:Promise<CollectionResource<TimeEntryResource>> };
+ protected memoizedTimeEntries:{ start:Moment, end:Moment, entries:Promise<CollectionResource<TimeEntryResource>> };
public memoizedCreateAllowed = false;
@@ -216,7 +216,9 @@ export class TimeEntryCalendarComponent {
successCallback:(events:EventInput[]) => void,
failureCallback:(error:Error) => void,
):void|PromiseLike<EventInput[]> {
- void this.fetchTimeEntries(fetchInfo.start, fetchInfo.end)
+ const start = moment(fetchInfo.startStr);
+ const end = moment(fetchInfo.endStr);
+ void this.fetchTimeEntries(start, end)
.then(async (collection) => {
this.entries.emit(collection);
@@ -225,10 +227,10 @@ export class TimeEntryCalendarComponent {
.catch(failureCallback);
}
- protected fetchTimeEntries(start:Date, end:Date):Promise<CollectionResource<TimeEntryResource>> {
+ protected fetchTimeEntries(start:Moment, end:Moment):Promise<CollectionResource<TimeEntryResource>> {
if (!this.memoizedTimeEntries
- || this.memoizedTimeEntries.start.getTime() !== start.getTime()
- || this.memoizedTimeEntries.end.getTime() !== end.getTime()) {
+ || this.memoizedTimeEntries.start.valueOf() !== start.valueOf()
+ || this.memoizedTimeEntries.end.valueOf() !== end.valueOf()) {
const promise = firstValueFrom(
this
.apiV3Service
@@ -388,9 +390,9 @@ export class TimeEntryCalendarComponent {
};
}
- protected dmFilters(start:Date, end:Date):Array<[string, FilterOperator, string[]]> {
- const startDate = moment(start).format('YYYY-MM-DD');
- const endDate = moment(end).subtract(1, 'd').format('YYYY-MM-DD');
+ protected dmFilters(start:Moment, end:Moment):Array<[string, FilterOperator, string[]]> {
+ const startDate = start.format('YYYY-MM-DD');
+ const endDate = end.subtract(1, 'd').format('YYYY-MM-DD');
return [['spentOn', '<>d', [startDate, endDate]] as [string, FilterOperator, string[]],
['user_id', '=', ['me']] as [string, FilterOperator, [string]]];
}
@@ -399,7 +401,7 @@ export class TimeEntryCalendarComponent {
if (event.event.extendedProps.entry) {
this.editEvent(event.event.extendedProps.entry);
} else if (event.el.classList.contains(ADD_ENTRY_CLASS_NAME) && !event.el.classList.contains(ADD_ENTRY_PROHIBITED_CLASS_NAME)) {
- this.addEvent(moment(event.event.start));
+ this.addEvent(moment(event.event.startStr));
}
}
@@ -420,7 +422,7 @@ export class TimeEntryCalendarComponent {
// Use end instead of start as when dragging, the event might be too long and would thus be start
// on the day before by fullcalendar.
- entry.spentOn = moment(event.event.end).format('YYYY-MM-DD');
+ entry.spentOn = moment(event.event.endStr).format('YYYY-MM-DD');
void this
.schemaCache
diff --git a/modules/my_page/spec/features/my/my_spent_time_widget_with_a_negative_time_zone_spec.rb b/modules/my_page/spec/features/my/my_spent_time_widget_with_a_negative_time_zone_spec.rb
new file mode 100644
index 00000000000..664477503f2
--- /dev/null
+++ b/modules/my_page/spec/features/my/my_spent_time_widget_with_a_negative_time_zone_spec.rb
@@ -0,0 +1,103 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require 'spec_helper'
+
+require_relative '../../support/pages/my/page'
+
+RSpec.describe 'My spent time widget with a negative time zone', :js,
+ with_settings: { start_of_week: 1 } do
+ let(:beginning_of_week) { monday }
+ let(:end_of_week) { sunday }
+ let(:monday) { Date.current.beginning_of_week(:monday) }
+ let(:tuesday) { beginning_of_week + 1.day }
+ let(:thursday) { beginning_of_week + 3.days }
+ let(:sunday) { beginning_of_week + 6.days }
+ let(:time_zone) { 'America/Phoenix' }
+
+ let!(:type) { create(:type) }
+ let!(:project) { create(:project, types: [type]) }
+ let!(:activity) { create(:time_entry_activity, name: 'Development') }
+ let!(:work_package) do
+ create(:work_package,
+ project:,
+ type:,
+ author: user)
+ end
+ let!(:time_entry) do
+ create(:time_entry,
+ spent_on: monday,
+ work_package:,
+ project:,
+ activity:,
+ user:)
+ end
+ let(:user) do
+ create(:user,
+ preferences: { time_zone: },
+ member_in_project: project,
+ member_with_permissions: %i[view_time_entries edit_time_entries view_work_packages log_own_time])
+ end
+ let(:my_page) { Pages::My::Page.new }
+ let(:time_logging_modal) { Components::TimeLoggingModal.new }
+ let!(:week_days) { week_with_saturday_and_sunday_as_weekend }
+ let!(:non_working_day) { create(:non_working_day, date: tuesday) }
+
+ # Configure the time zone of the browser
+ # @param [String] time_zone The time zone to set, for instance 'Europe/Paris'
+ def set_browser_time_zone(time_zone)
+ page.driver.browser.execute_cdp('Emulation.setTimezoneOverride', timezoneId: time_zone)
+ end
+
+ before do
+ login_as user
+ set_browser_time_zone(time_zone)
+ my_page.visit!
+ end
+
+ it 'correctly displays non-working days and prefills day when logging time [fix #49779]' do
+ my_page.add_widget(1, 1, :within, 'My spent time')
+
+ my_page.expect_and_dismiss_toaster message: I18n.t(:notice_successful_update)
+
+ aggregate_failures("non-working days are displayed properly") do
+ expect(page).not_to have_css('.fc-day-mon.fc-non-working-day', wait: 0)
+ expect(page).to have_css('.fc-day-tue.fc-non-working-day', wait: 0)
+ expect(page).not_to have_css('.fc-day-wed.fc-non-working-day', wait: 0)
+ expect(page).not_to have_css('.fc-day-thu.fc-non-working-day', wait: 0)
+ expect(page).not_to have_css('.fc-day-fri.fc-non-working-day', wait: 0)
+ expect(page).to have_css('.fc-day-sat.fc-non-working-day', wait: 0)
+ expect(page).to have_css('.fc-day-sun.fc-non-working-day', wait: 0)
+ end
+
+ aggregate_failures("when clicking a day, time entry day is set to the day clicked (Thursday)") do
+ find(".fc-day-thu .te-calendar--add-entry", visible: false).click
+ time_logging_modal.has_field_with_value 'spentOn', thursday.iso8601
+ end
+ end
+end