Merge delay time updates every edit if server timezone is not UTC

Summary

Self managed installations with a non-UTC timezone set will have the "Merge can start" time change every time they edit the MR.

The feature to delay MRs was added in 17.6.1:

Schedule MR to be automatically merged based on... (#14380 - closed)

Steps to reproduce

  1. Optional: Before setting changing the default timezone, create a merge request with a delay. When you edit the MR, the time set for the delay should not change.

  2. Change your timezone to a non-UTC region: gitlab_rails['time_zone'] = 'Japan'

  3. Once reconfigured and restarted, create a new MR and schedule the delay for after 11:30 AM

  4. Once created the MR will show that it cannot be merged until after 11:30AM

    Screenshot 2025-01-09 at 11.44.14.png

  5. Edit the MR. Observe that the delay time is automatically moved 9 hours ahead to 8:30 PM / 20:30

    Screenshot 2025-01-09 at 11.45.25.png

  6. This process will continue every time the MR is edited

What is the current bug behavior?

Merge delay time will be updated every time the MR is edited to convert the time to UTC. So for a server on JST, this will move the delay time forward another 9 hours (UTC+9). In EST, this will be shifted by 5 hours (UTC-5). If a user does not notice this change, they will further delay the merge request.

The time set in the UI seems to be based on the user's current timezone. It is saved with the server set timezone. It then appears to be converted to UTC time every time it is edited.

For example, I am based in UTC+13 timezone, but set my server to JST (UTC+9). When I set the merge delay to Jan 10, 2025, 11:30 AM, the MR API data shows the merge_after date with reference to UTC+9

merge_after "2025-01-10T07:30:00.000+09:00"

When I edit the Merge Request, the delay time field jumps forward 9 hours to what would be UTC+0 time. However, since it seems to still consider this my local time, it keeps causing the time to jump forward every time it is edited. So if I save the the MR without noticing, the new times will show it's jumped forward 9 hours:

UI:

UTC+13 time

Cannot merge until Jan 10, 2025, 20:30

API:

UTC+9 time

merge_after "2025-01-10T16:30:00.000+09:00"

What is the expected correct behavior?

The time would not change unless explicitly edited by the user.

Relevant logs and/or screenshots

Screen Recording 2025-01-09 at 11.36.42.mov

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

System information System: Ubuntu 20.04 Proxy: no Current User: git Using RVM: no Ruby Version: 3.2.5 Gem Version: 3.5.23 Bundler Version:2.5.11 Rake Version: 13.0.6 Redis Version: 7.0.15 Sidekiq Version:7.2.4 Go Version: unknown

GitLab information Version: 17.6.1-ee Revision: 5f698b15f67 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 14.11 URL: https://irisb-latest.env-a72a3647.gcp.gitlabsandbox.net HTTP Clone URL: https://irisb-latest.env-a72a3647.gcp.gitlabsandbox.net/some-group/some-project.git SSH Clone URL: git@irisb-latest.env-a72a3647.gcp.gitlabsandbox.net:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers:

GitLab Shell Version: 14.39.0 Repository storages:

- default: unix:/var/opt/gitlab/gitaly/gitaly.socket GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell

Gitaly

- default Address: unix:/var/opt/gitlab/gitaly/gitaly.socket
- default Version: 17.6.1
- default Git Version: 2.47.0

Results of GitLab application Check

Expand for output related to the GitLab application check

System information System: Ubuntu 20.04 Proxy: no Current User: git Using RVM: no Ruby Version: 3.2.5 Gem Version: 3.5.23 Bundler Version:2.5.11 Rake Version: 13.0.6 Redis Version: 7.0.15 Sidekiq Version:7.2.4 Go Version: unknown

GitLab information Version: 17.6.1-ee Revision: 5f698b15f67 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 14.11 URL: https://irisb-latest.env-a72a3647.gcp.gitlabsandbox.net HTTP Clone URL: https://irisb-latest.env-a72a3647.gcp.gitlabsandbox.net/some-group/some-project.git SSH Clone URL: git@irisb-latest.env-a72a3647.gcp.gitlabsandbox.net:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers:

GitLab Shell Version: 14.39.0 Repository storages:

- default: unix:/var/opt/gitlab/gitaly/gitaly.socket GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell

Gitaly

- default Address: unix:/var/opt/gitlab/gitaly/gitaly.socket
- default Version: 17.6.1
- default Git Version: 2.47.0 iblackburn@irisb-latest:\~$ sudo gitlab-rake gitlab:check SANITIZE=true Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version \>= 14.39.0 ? ... OK (14.39.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell-check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... yes Number of Sidekiq processes (cluster/worker) ... 1/1

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Database config exists? ... yes Tables are truncated? ... skipped All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Cable config exists? ... yes Resque config exists? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Systemd unit files or init script exist? ... skipped (omnibus-gitlab has neither init script nor systemd units) Systemd unit files or init script up-to-date? ... skipped (omnibus-gitlab has neither init script nor systemd units) Projects have namespace: ... 1/1 ... yes 5/2 ... yes 7/3 ... yes Redis version \>= 6.2.14? ... yes Ruby version \>= 3.0.6 ? ... yes (3.2.5) Git user has default SSH configuration? ... yes Active users: ... 3 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x-8.x or OpenSearch version 1.x ... skipped (Advanced Search is disabled) All migrations must be finished before doing a major upgrade ... skipped (Advanced Search is disabled)

Checking GitLab App ... Finished

Checking GitLab subtasks ... Finished

Possible fixes

The issue appears related to this line which seems to converting the time to UTC, thus adding the offset time difference.

merge_after: issuable.merge_schedule&.merge_after&.strftime('%Y-%m-%dT%H:%MZ'),