• Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major Major
    • core
    • None
    • Platform: All, OS: All

      My company has employees in different time zones, but since you can only
      configure Java to use one timezone, we can only make one group of users see the
      "right" time from hudson.

      You can detect the timezone from Javascript
      (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/),
      so I suggest the following approach to using a user's timezone:
      Detect the browser's timezone on the first page load
      Set a cookie with the timezone in it
      On subsequent page view, use the timezone stored in the cookie. Fall back to the
      system time zone.

          [JENKINS-1962] Detect timezone from browser

          The core problem is that each user can have a different timezone. This means that you are annoying the heck out of some people.

          Some things to mitigate this include:

          1) Using more relative times. These are always useful, though they become stale if the page isn't refreshed or reloaded.
          2) Adding timezones to times. (e.g. JENKINS-13092)

          Re: detecting from the browser – I like this, but instead of putting it in a cookie, put it in the user's profile if it isn't set there. Some authentication strategies (e.g. OpenID, LDAP, etc.) can have TZ information that can be used – in those cases, it shouldn't be set based on browser's timezone.

          Ciao!

          Christian Höltje added a comment - The core problem is that each user can have a different timezone. This means that you are annoying the heck out of some people. Some things to mitigate this include: 1) Using more relative times. These are always useful, though they become stale if the page isn't refreshed or reloaded. 2) Adding timezones to times. (e.g. JENKINS-13092 ) Re: detecting from the browser – I like this, but instead of putting it in a cookie, put it in the user's profile if it isn't set there. Some authentication strategies (e.g. OpenID, LDAP, etc.) can have TZ information that can be used – in those cases, it shouldn't be set based on browser's timezone. Ciao!

          +1
          Having the timezone (e.g. UTC) in the shown time would be a really great feature!

          Matteo Castellarin added a comment - +1 Having the timezone (e.g. UTC) in the shown time would be a really great feature!

          Seeing as this issue is very old, there have been some improvements to how browsers support locales since it was raised.

          https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat has some documentation.

          Running this code on a webdeveloper console in a browser shows multiple formats that are appropriate for the user's locale.

          var dateStyles = ['full', 'long', 'medium', 'short'];
          var timeStyles = ['full', 'long', 'medium', 'short'];
          var result = [];
          dateStyles.forEach(d => {
              timeStyles.forEach(t => {
                  result.push({
                      dateStyle: d, timeStyle: t,
                      formatted: new Intl.DateTimeFormat(navigator.language, {dateStyle: d, timeStyle: t}).format(Date.now())});
              });
            console.log(d);
          });
          console.table(result);

          I would like to take a stab at this by replacing any time being printed on a page with a custom tag like this:

          <timestamp value="${iso8601Timestamp}" dateStyle="?" timeStyle="?"></timestamp>
          

          Then I would like to follow up by running some javascript on page load that updates the body of all timestamp tags with the result of using the browser's native formatter.

          The downside of this approach is we can't always match the format used currently. The upside is, we can localize time adequately.

          Rahul Somasunderam added a comment - Seeing as this issue is very old, there have been some improvements to how browsers support locales since it was raised. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat  has some documentation. Running this code on a webdeveloper console in a browser shows multiple formats that are appropriate for the user's locale. var dateStyles = [ 'full' , ' long ' , 'medium' , ' short ' ]; var timeStyles = [ 'full' , ' long ' , 'medium' , ' short ' ]; var result = []; dateStyles.forEach(d => { timeStyles.forEach(t => { result.push({ dateStyle: d, timeStyle: t, formatted: new Intl.DateTimeFormat(navigator.language, {dateStyle: d, timeStyle: t}).format(Date.now())}); }); console.log(d); }); console.table(result); I would like to take a stab at this by replacing any time being printed on a page with a custom tag like this: <timestamp value= "${iso8601Timestamp}" dateStyle= "?" timeStyle= "?" > </timestamp> Then I would like to follow up by running some javascript on page load that updates the body of all timestamp tags with the result of using the browser's native formatter. The downside of this approach is we can't always match the format used currently. The upside is, we can localize time adequately.

            Unassigned Unassigned
            candrews candrews
            Votes:
            64 Vote for this issue
            Watchers:
            42 Start watching this issue

              Created:
              Updated: