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

hour difference for different years in wasm32 #413

Closed
sergeyt opened this issue Apr 15, 2020 · 1 comment
Closed

hour difference for different years in wasm32 #413

sergeyt opened this issue Apr 15, 2020 · 1 comment

Comments

@sergeyt
Copy link
Contributor

sergeyt commented Apr 15, 2020

I'm trying to use chrono strftime in wasm.
I'm getting strange hour difference when trying to format timestamp passed from JavaScript.

I've created this repo to reproduce the issue.

I have the following function:

extern crate chrono;

use wasm_bindgen::prelude::*;
use chrono::prelude::*;

#[wasm_bindgen]
pub fn format_strftime(format: &str, timestamp: f64) -> String {
    let off = Local::now().offset().fix();
    let d = off.timestamp_millis(timestamp as i64);
    return d.format(format).to_string();
}

and this test is failing

/**
 * @jest-environment node
 */
const wasm = require("../pkg/index.js");

describe("chrono", () => {
  it("hour diff", () => {
    let diffs: any = {};
    for (let y = 0; y <= 2020; y++) {
      const d = new Date();
      d.setFullYear(y);
      d.setHours(13);
      const expected = String(d.getHours());
      const actual = wasm.format_strftime("%H", d.getTime());
      if (actual !== expected) {
        const key = String(parseInt(expected, 10) - parseInt(actual, 10));
        const dif = diffs[key] || (diffs[key] = { ranges: [] });
        const range = dif.ranges.find((r) => y >= r[0] && y <= r[1] + 1);
        if (range) {
          range[1] = y;
        } else {
          dif.ranges.push([y, y]);
        }
      }
    }
    console.log(JSON.stringify(diffs, null, "  "));
    expect(Object.keys(diffs).length).toBe(0);
  });
});

I expect no difference, but this test prints the following difference:

{
      "1": {
        "ranges": [
          [
            1981,
            1990
          ],
          [
            1992,
            1993
          ]
        ]
      },
      "-1": {
        "ranges": [
          [
            0,
            1930
          ],
          [
            2015,
            2016
          ]
        ]
      }
    }

Steps to reproduce:

I am running the test in nodejs environment.

I guess issue #391 is related to this somehow.

@sergeyt sergeyt changed the title hour difference in wasm32 hour difference for different years in wasm32 Apr 15, 2020
@pitdicker
Copy link
Collaborator

I can't easily run the included test here, but #1131 fixes what I believe is this issue.

@djc djc closed this as completed Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants