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

time.js uses inconsistenly zone and timezone #795

Open
dilyanpalauzov opened this issue Nov 9, 2024 · 0 comments
Open

time.js uses inconsistenly zone and timezone #795

dilyanpalauzov opened this issue Nov 9, 2024 · 0 comments

Comments

@dilyanpalauzov
Copy link
Contributor

Time.constructor accepts two parameters: data and zone, and calls then this.fromData(data, zone);

fromData() accepts two pamameters: aData and aZone. Here aZone is optional, so the zone parameters of the constructor should also be optional, but is not.

In static time.fromData timezone is also optional. So, again, the type annotations for zone in time.constructor should be changed to optional.

Besides, time.resetTo() passes zone as the first parameter to this.fromData, not as second. Likewise for time.getEpochTime(). That said, the typescript rules exported by ical.js were not applied towards the code of ical.js itself.

time.fromData is implemented as:

    if (aData) {
      for (let [key, value] of Object.entries(aData)) {
          // ical type cannot be set                                                                                                    
          if (key === 'icaltype') continue;
        this[key] = value;
      }
    }

    if (aZone) {
      this.zone = aZone;
    }

So time.getEpoch() creates this.#epochTime with member timezone, but it should set zone instead.

Finally fromData handles in aData as parameters zone and timezone the same way, but neither of these parameters are allowed by the type definitions of the function.

  • Make clearer whether the time member should be called zone or timezone and use this consistently.
  • Make timezone parameter of time.constructor() optional and allow zone as member of the first parameter. zone as first parameter has worked, before introducing the types.
  • In static get epochTime change timezone with zone
  • Possibly in fromDateTimeString() change timeData.zone = zoneId; to timeData.zone = zoneId;
  • If fromData checks if (aData && "timezone" in aData) and if (aData && "zone" in aData) consider adding the zone and timezone parameters to the type of aData.
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

1 participant