Skip to content

Conversation

@itingliu
Copy link
Contributor

@itingliu itingliu commented Jan 4, 2024

Calendar's weekend support requires the following functions:

  1. isDateInWeekend: answers whether a given date is in weekend
  2. weekendRange: function that returns the days and times of the weekend

This implements the first. The second one, weekend range, is in fact related to calendar's locale rather than calendar itself. Move it over to _LocaleProtocol and have locale handle it.

@itingliu itingliu requested a review from parkera January 4, 2024 18:51
@itingliu
Copy link
Contributor Author

itingliu commented Jan 4, 2024

@swift-ci please test

var cease: UInt32?

var status = U_ZERO_ERROR
let cal = ucal_open(nil, 0, identifier, UCAL_DEFAULT, &status)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it going to be more expensive (CPU time) to open and close the calendar here, vs on Calendar_ICU where we reuse the ucalendar we already had?

I don't think it is a showstopper, because this makes a lot more sense, but we should be aware.

Copy link
Contributor Author

@itingliu itingliu Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see an obvious performance regression. This value is cached inside this _LocaleICU instance, so we'd only call ucal_open once per Calendar-Locale combination. Since we're also caching locale by its identifier, we'd be fetching from the cache most of the time.

Calendar's weekend support requires the following functions:
1. `isDateInWeekend`: answers whether a given date is in weekend
2. `weekendRange`: function that returns the days and times of the weekend

This implements the first. The second one, weekend range, is in fact related to calendar's locale rather than calendar itself. Move it over to `_LocaleProtocol` and have locale handle it.
@itingliu itingliu force-pushed the gregorian-calendar-weekend branch from 32aa198 to 55b9dbb Compare January 8, 2024 22:08
@itingliu itingliu merged commit d569316 into swiftlang:main Jan 9, 2024
@itingliu itingliu deleted the gregorian-calendar-weekend branch January 9, 2024 19:52
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

Successfully merging this pull request may close these issues.

2 participants