Skip to content

Use (NS)DateComponents instead of (NS)Date for DATE-TIME and DATE values #47

@tikitu

Description

@tikitu

Hi folks,

I'm wondering why XbICalendar uses NSDate to represent DATE-TIME and DATE properties, and whether NSDateComponents might be a better choice. In particular:

  • An NSDateComponents instance with hours/minutes/seconds unset is an apt representation for a "calendar date" (DATE).
  • An NSDateComponents instance with an explicit timezone is a better representation for a DATE-TIME, since the timezone component can be important for date-time arithmetic.

I'm not aware of any issues caused by the first point, it just "fits". The second, more important, point is what got me started on this. I'm working on a bug over in my fork which makes RRULE properties misbehave across a DST boundary: https://github.com/minddistrict/XbICalendar/tree/preserve-timezone-strings

The root cause is that when an DTSTART property makes a round-trip from icalproperty to XbICProperty and back to icalproperty it loses the original timezone, because XbICProperty represents it as NSDate which forgets its timezone information. (This makes sense. An NSDate represents an instant in time: two NSDate objects created from different timezones but identifying the same instant should compare equal, which implies forgetting the originating timezone.)

So I'm thinking that the "right" fix for that bug would be to convert to using NSDateComponents for DTSTART, which implies using them for all DATE-TIME properties, and then I might as well go ahead and convert DATE properties too.

My question for y'all is: am I missing some design considerations that make this a terrible idea? And if not, how do you rate the chances of landing a PR with these changes? It's a change to the external API of the library, so needs some release management.

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