Skip to content

analytics-utils: localTime() offset hour is wrong in negative half-hour timezones #524

Description

@sarmah-rup

localTime() in analytics-utils returns the wrong offset hour in negative half-hour timezones.

Steps to reproduce

process.env.TZ = 'Pacific/Marquesas'  // UTC-09:30
localTime().slice(-6)                 // "-10:30"

process.env.TZ = 'America/St_Johns'   // UTC-03:30 (UTC-02:30 in summer)
localTime().slice(-6)                 // "-04:30" (or "-03:30" in summer)

Expected
-09:30 and -03:30 (or -02:30).

Cause
The hour is built with pad(tzo / 60), and pad does Math.abs(Math.floor(n)). For UTC-09:30, Math.floor(-9.5) is -10, so the hour is off by one in every negative half-hour zone. Positive and whole-hour zones are fine.

Version: analytics-utils 1.1.1 (master)

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions