Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-19887

Allow time zone to be set on a per user basis

    Details

    • Type: Improvement
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: core
    • Labels:
      None
    • Similar Issues:
    • Released As:
      Jenkins 2.203

      Description

      Our Jenkins instances are used by users in multiple time zones. It would be nice if the user was able to set his/her time zone in user preferences, and for times to then be displayed local to that user.

        Attachments

          Issue Links

            Activity

            Hide
            jsoref Josh Soref added a comment -

            Note that momentjs will not work if the server already merges two date objects into some datedelta – https://github.com/jenkinsci/jenkins/pull/3525 will probably introduce a case where two dates are subtracted resulting in a number.

            Personally, I like the idea of using momentjs (or similar).

            Show
            jsoref Josh Soref added a comment - Note that momentjs will not work if the server already merges two date objects into some datedelta – https://github.com/jenkinsci/jenkins/pull/3525  will probably introduce a case where two dates are subtracted resulting in a number. Personally, I like the idea of using momentjs (or similar).
            Hide
            agentgt Adam Gent added a comment -

            I briefly looked around and this would not be that hard to implement if only you could get the root JellyContext.

            Once you have the JellyContext then just you just intercept the calls:
            JellyContext.getVariable(Config.FMT_TIME_ZONE);

            Or set the variable since the context is mutable.

            The JellyContext is already bound to a request via a ThreadLocal in ExpressionFactory2 so you just need to setup the parent JellyContext to look at user config.

            The problem is that Stapler makes its own JellyContext called CustomJellyContext in DefaultScriptInvoker per request (which is good)!

            So in theory a custom DefaultScriptInvoker that pulls user configuration logic and sets the context with that user logic should be able to set the correct time zone variable.

             

             

            Show
            agentgt Adam Gent added a comment - I briefly looked around and this would not be that hard to implement if only you could get the root JellyContext. Once you have the JellyContext then just you just intercept the calls: JellyContext.getVariable(Config.FMT_TIME_ZONE); Or set the variable since the context is mutable. The JellyContext is already bound to a request via a ThreadLocal in ExpressionFactory2 so you just need to setup the parent JellyContext to look at user config. The problem is that Stapler makes its own JellyContext called CustomJellyContext in DefaultScriptInvoker per request (which is good)! So in theory a custom DefaultScriptInvoker that pulls user configuration logic and sets the context with that user logic should be able to set the correct time zone variable.    
            Hide
            mcmoe Morgan Kobeissi added a comment -

            As a workaround, I added the below script to my tampermonkey extension in Chrome. This allows me to view the dates in a job in my computer's timezone. Might be of interest to some of you.

             

            // ==UserScript==
            // @name         Local Jenkins job dates
            // @namespace    http://tampermonkey.net/
            // @version      0.1
            // @description  use local date for Jenkins jobs
            // @author       You
            // @match        https://myjenkinsdomain.com/job/*
            // @grant        none
            // ==/UserScript==(function() {
                'use strict';    const allTimes = document.querySelectorAll('div[time]');
                allTimes.forEach(d => {d.textContent = new Date(+d.getAttribute('time')).toLocaleString('en-US', {day: "2-digit", month: "short", year: "numeric", hour: "numeric", minute: "numeric"});});
            })(); 
            Show
            mcmoe Morgan Kobeissi added a comment - As a workaround, I added the below script to my tampermonkey extension in Chrome. This allows me to view the dates in a job in my computer's timezone. Might be of interest to some of you.   // ==UserScript== // @name Local Jenkins job dates // @namespace http://tampermonkey.net/ // @version 0.1 // @description use local date for Jenkins jobs // @author You // @match https://myjenkinsdomain.com/job/* // @grant none // ==/UserScript==(function() { 'use strict' ; const allTimes = document.querySelectorAll( 'div[time]' ); allTimes.forEach(d => {d.textContent = new Date(+d.getAttribute( 'time' )).toLocaleString( 'en-US' , {day: "2-digit" , month: " short " , year: "numeric" , hour: "numeric" , minute: "numeric" });}); })();
            Hide
            jonhermansen Jon Hermansen added a comment -

            Thank you Morgan Kobeissi for the userscript!

            Show
            jonhermansen Jon Hermansen added a comment - Thank you Morgan Kobeissi for the userscript!
            Hide
            oleg_nenashev Oleg Nenashev added a comment -

            The feature has been released in Jenkins 2.203. It has a good chance to appear in the next LTS

            Show
            oleg_nenashev Oleg Nenashev added a comment - The feature has been released in Jenkins 2.203. It has a good chance to appear in the next LTS

              People

              • Assignee:
                Unassigned
                Reporter:
                brianegge Brian Egge
              • Votes:
                74 Vote for this issue
                Watchers:
                55 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: