Skip to content

HDateTime.toString() returns incorrect value when timezone is different than system time #30

Description

@kianj2

HDateTime.toString() displays the correct timezone. However, it displays the wrong time. Consider the following code snippet

import { HDateTime } from "haystack-core";

const now = new Date().toISOString();

// 2023-10-12T23:53:04.861Z
console.log(now);

const value = HDateTime.make({
  val: now,
  tz: "America/New_York"
}).toString();

// 10/12/2023, 4:53:04 PM America/New_York
console.log(value);

The string value of "10/12/2023, 4:53:04 PM" is incorrect. The correct string should be "10/12/2023, 7:53:04 PM". I believe this is because toString() uses Date.toLocaleString(), which I am assuming is creating a locale string for the local system time.

public toString(): string {

public toString(): string {
  return (
    this.date.toLocaleString() +
    (this.timezone ? ` ${this.timezone}` : '')
  )
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions