Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Sources/FoundationEssentials/Calendar/Calendar_Gregorian.swift
Original file line number Diff line number Diff line change
Expand Up @@ -846,15 +846,15 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
if startAtUnit == .day || startAtUnit == .weekday || startAtUnit == .weekdayOrdinal {
let targetDay = dateComponent(.day, from: updatedDate)
var currentDay = targetDay
var udate = updatedDate
var update = updatedDate
var prev: Date
repeat {
prev = udate
Copy link
Contributor

Choose a reason for hiding this comment

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

I personally prefer not having a particular commit just to change internal variable names, even if they're not perfect. I'd only do so when there's a strong reason for changing them, or do it as part of a bug fix or feature work. This way we still have access to the commit history.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually combined multiple commits into a single PR to address this concern. These are all typos in Calendar within FoundationEssentials that Xcode underlines. Please let me know if you’d like me to drop any of these comments from the PR or rebase the result.

Thanks!

P.S. There is a type named "UDate"Format, so this particular typo might cause some confusion for readers.

udate = try self.add(.second, to: prev, amount: -1, inTimeZone: timeZone)
guard udate < prev else {
throw GregorianCalendarError.notAdvancing(udate, prev)
prev = update
update = try self.add(.second, to: prev, amount: -1, inTimeZone: timeZone)
guard update < prev else {
throw GregorianCalendarError.notAdvancing(update, prev)
}
currentDay = dateComponent(.day, from: udate)
currentDay = dateComponent(.day, from: update)
} while targetDay == currentDay

start = prev
Expand Down Expand Up @@ -989,13 +989,13 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable

case .weekOfYear, .weekOfMonth: /* kCFCalendarUnitWeek_Deprecated */
guard var start = start(of: .era, at: date) else { return nil }
var (startMatchinWeekday, daysAdded) = try dateAfterDateWithTargetDoW(start, firstWeekday)
var (startMatchingWeekday, daysAdded) = try dateAfterDateWithTargetDoW(start, firstWeekday)

start += Double(daysAdded) * 86400.0

if minimumDaysInFirstWeek <= daysAdded {
// previous week chunk was big enough, count it
startMatchinWeekday -= 7 * 86400.0
startMatchingWeekday -= 7 * 86400.0
start -= 7 * 86400.0
}
var week = Int(floor(
Expand Down Expand Up @@ -2272,7 +2272,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable

switch field {
case .era:
// We've been ignorning era historically. Do the same for compatibility reason.
// We've been ignoring era historically. Do the same for compatibility reason.
return date

case .yearForWeekOfYear:
Expand Down Expand Up @@ -2395,7 +2395,7 @@ internal final class _CalendarGregorian: _CalendarProtocol, @unchecked Sendable
let newOffset = timeZone.secondsFromGMT(for: newDateInWholeSecond)
let prevOffset = timeZone.secondsFromGMT(for: date)

// No need for normal gmt-offset adjustment because the revelant bits are handled above individually
// No need for normal gmt-offset adjustment because the relevant bits are handled above individually
// We do have to adjust DST offset when the new date crosses DST boundary, such as adding an hour to dst transitioning day
if newOffset != prevOffset {
newDateInWholeSecond = newDateInWholeSecond + Double(prevOffset - newOffset)
Expand Down
20 changes: 10 additions & 10 deletions Sources/FoundationEssentials/Calendar/Calendar_Recurrence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
// Recurrence enumeration
//
// This file implements enumerating occurences according to a recurrence rule as
// This file implements enumerating occurrences according to a recurrence rule as
// specified in RFC5545 and RFC7529

extension Calendar.RecurrenceRule.Frequency {
Expand Down Expand Up @@ -623,11 +623,11 @@ extension Calendar {
/// - parent: .year if the frequency is yearly, otherwise .month
/// - anchor: a date around which to perform the expansion
/// - Returns: array of `DateComponents`, which can be used to enumerate all
/// weekdays of intereset, or to filter a list of dates
/// weekdays of interest, or to filter a list of dates
func _weekdayComponents(for weekdays: [Calendar.RecurrenceRule.Weekday],
in parent: Calendar.Component,
anchor: Date) -> [DateComponents]? {
/// Map of weekdays to which occurences of the weekday we are interested
/// Map of weekdays to which occurrences of the weekday we are interested
/// in. `1` is the first such weekday in the interval, `-1` is the last.
/// An empty array indicates that any weekday is valid
var map: [Locale.Weekday: [Int]] = [:]
Expand All @@ -650,7 +650,7 @@ extension Calendar {
// necessarily occur in the first week of the month.

/// The component where we set the week number, if we are targeting only
/// a particular occurence of a weekday
/// a particular occurrence of a weekday
let weekComponent: Calendar.Component = if parent == .month {
.weekOfMonth
} else {
Expand All @@ -671,22 +671,22 @@ extension Calendar {
// few seconds can give us the last day in the interval
lazy var lastWeekday = component(.weekday, from: interval.end.addingTimeInterval(-0.1))

for (weekday, occurences) in map {
for (weekday, occurrences) in map {
let weekdayIdx = weekday.icuIndex
if occurences == [] {
if occurrences == [] {
var components = DateComponents()
components.setValue(nil, for: weekComponent)
components.weekday = weekdayIdx
result.append(components)
} else {
lazy var firstWeek = weekRange.lowerBound + (weekdayIdx < firstWeekday ? 1 : 0)
lazy var lastWeek = weekRange.upperBound - (weekdayIdx > lastWeekday ? 1 : 0)
for occurence in occurences {
for occurrence in occurrences {
var components = DateComponents()
if occurence > 0 {
components.setValue(firstWeek - 1 + occurence, for: weekComponent)
if occurrence > 0 {
components.setValue(firstWeek - 1 + occurrence, for: weekComponent)
} else {
components.setValue(lastWeek + occurence, for: weekComponent)
components.setValue(lastWeek + occurrence, for: weekComponent)
}
components.weekday = weekdayIdx
result.append(components)
Expand Down
2 changes: 1 addition & 1 deletion Sources/FoundationEssentials/Calendar/DateComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public struct DateComponents : Hashable, Equatable, Sendable {

// MARK: -

/// Returns a new `DateComponents` where the subset of fields that can be scaled have been mulitplied by `value`.
/// Returns a new `DateComponents` where the subset of fields that can be scaled have been multiplied by `value`.
internal func scaled(by value: Int) -> DateComponents {
var dc = self
if let era = _era { dc.era = era * value }
Expand Down