Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS broken when LOCALISE_TIMESTAMP set to False #461

Closed
volans- opened this issue Apr 13, 2018 · 4 comments · Fixed by #722
Closed

JS broken when LOCALISE_TIMESTAMP set to False #461

volans- opened this issue Apr 13, 2018 · 4 comments · Fixed by #722
Labels

Comments

@volans-
Copy link
Contributor

volans- commented Apr 13, 2018

In _macros.html#L71 there is a call to localise_timestamp() that is done independently of the LOCALISE_TIMESTAMP setting. When LOCALISE_TIMESTAMP is set to False, moment.js is not loaded at all (see layout.html) resulting in JS errors:

Uncaught TypeError: $(...).localise_timestamp is not a function

Ideally even when LOCALISE_TIMESTAMP is set to False the timestamps should be properly formatted in a nice way, just preserving the original times without TZ conversion.

As a side note the README is a bit confusing regarding this option given that it states:

LOCALISE_TIMESTAMP: Normalize time based on localserver time.

While it seems to me that it normalize it to the client's time when set to True.

@emlun007
Copy link
Contributor

emlun007 commented May 1, 2018

moment.js should be loaded in any case to get proper formatting of the data:

{% if config.OFFLINE_MODE %}

      <script src="{{ url_for('static', filename='jquery-2.1.1/jquery.min.js') }}"></script>
      <script src="{{ url_for('static', filename='jquery-datatables-1.10.13/jquery.dataTables.min.js') }}">
      <script src="{{ url_for('static', filename='jquery-datatables-1.10.13/dataTables.semanticui.min.js') }}">
      <script src="{{ url_for('static', filename='moment.js-2.7.0/moment.min.js') }}"></script>

So to get a nice formatting, just without TZ conversion, in timestamps.js you can just remove the line:
result.local();

to get the data in utc, so something like:

$.fn.extend({
  localise_timestamp: function (){
    var tstring = $(this).text().trim();
    if (tstring === "None"){
      $(this).text('Unknown');
    } else {
      var result = moment(tstring).utc();
      $(this).text(result.format('MMM DD YYYY - HH:mm:ss'));
    }
  }
})

@gdubicki gdubicki added the bug label Feb 5, 2022
gdubicki added a commit that referenced this issue Oct 23, 2022
@gdubicki
Copy link
Contributor

gdubicki commented Oct 23, 2022

Hi @volans-!

The code you mentioned has been changed in #708 but I noticed today that LOCALISE_TIMESTAMP=False still did not work.

But I created #722 that should make it work and correct the docs, as you suggested.

@volans-
Copy link
Contributor Author

volans- commented Oct 24, 2022

@gdubicki Thanks for the follow up.

@gdubicki
Copy link
Contributor

Fix released in v4.2.1 today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants