Skip to content

Commit

Permalink
fixed rosh chodesh formatting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Smith committed Mar 10, 2024
1 parent 787cd5a commit 9dce266
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 9 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,118 @@
uuid = "FFB7797F-2A2E-4273-9A67-ACF903FC21F7"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "CC4D0E7D-1102-426E-9102-0AA1169643BA"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/KosherSwift/HebrewCalendar/HebrewDateFormatter.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "478"
endingLineNumber = "478"
landmarkName = "formatRoshChodesh(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "B6CCC76F-D982-4879-9346-BF75B4777CD5"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/KosherSwift/HebrewCalendar/HebrewDateFormatter.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "479"
endingLineNumber = "479"
landmarkName = "formatRoshChodesh(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "3DEBE218-F557-4760-BE1F-A1401DFDF1E0"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/KosherSwift/HebrewCalendar/HebrewDateFormatter.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "474"
endingLineNumber = "474"
landmarkName = "formatRoshChodesh(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "4BBFC4FA-2CD1-48E9-B0DE-A1E57234A08B"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/KosherSwift/HebrewCalendar/HebrewDateFormatter.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "472"
endingLineNumber = "472"
landmarkName = "formatRoshChodesh(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "E4BA8FEE-3195-4A2A-99E9-3CF911AF2678"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/KosherSwift/HebrewCalendar/JewishCalendar.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "18"
endingLineNumber = "18"
landmarkName = "init(withJewishYear:andMonth:andDay:isInIsrael:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "362D6D91-1975-4BC0-A0F5-01B67E190325"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/KosherSwift/HebrewCalendar/JewishCalendar.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "19"
endingLineNumber = "19"
landmarkName = "init(withJewishYear:andMonth:andDay:isInIsrael:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "D909FB94-975E-415E-9295-817BE5A1A88A"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/KosherSwift/HebrewCalendar/JewishCalendar.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "20"
endingLineNumber = "20"
landmarkName = "init(withJewishYear:andMonth:andDay:isInIsrael:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
4 changes: 2 additions & 2 deletions Sources/KosherSwift/HebrewCalendar/HebrewDateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public struct HebrewDateFormatter {
}
}

let tempCal = jewishCalendar.copy(month: month)
let tempCal = jewishCalendar.copy(month: month, day: 1)
formattedRoshChodesh = hebrewFormat
? (useShortHolidayFormat
? HebrewDateFormatter.hebrewShortHolidays[JewishHoliday.roshChodesh.rawValue]
Expand Down Expand Up @@ -510,7 +510,7 @@ public struct HebrewDateFormatter {
}

// This method is only about formatting, so we shouldn"t make any changes to the params passed in...
let tempCal = cal.copy(month: month)
let tempCal = cal.copy(month: month, day: 1)
formattedErevRoshChodesh = hebrewFormat
? (useShortHolidayFormat
? HebrewDateFormatter.hebrewShortHolidays[JewishHoliday.erevRoshChodesh.rawValue]
Expand Down
6 changes: 3 additions & 3 deletions Sources/KosherSwift/HebrewCalendar/JewishCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class JewishCalendar: JewishDate {
var hebCal = Calendar(identifier: .hebrew)
hebCal.timeZone = Calendar.current.timeZone


let gregDate = hebCal.date(from: DateComponents(year: year, month: month.toSwiftCalMonth(JewishDate.isJewishLeapYear(year)), day: day))!
let newMonth = month.toSwiftCalMonth(JewishDate.isJewishLeapYear(year))
let gregDate = hebCal.date(from: DateComponents(year: year, month: newMonth, day: day))!
self.init(date: gregDate, isInIsrael: isInIsrael)
}

Expand All @@ -29,7 +29,7 @@ public class JewishCalendar: JewishDate {
}

public func copy(year: Int? = nil, month: JewishMonth? = nil, day: Int? = nil, isInIsrael: Bool? = nil) -> JewishCalendar {
JewishCalendar(withJewishYear: year ?? self.year, andMonth: month ?? self.month, andDay: day ?? self.day, isInIsrael: isInIsrael ?? self.isInIsrael)
JewishCalendar(withJewishYear: year ?? self.year, andMonth: (month ?? self.month), andDay: day ?? self.day, isInIsrael: isInIsrael ?? self.isInIsrael)
}

public var isBirkasHachama: Bool {
Expand Down
5 changes: 3 additions & 2 deletions Sources/KosherSwift/HebrewCalendar/JewishDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ public class JewishDate: Comparable {
init(date: Date, includeTime: Bool = false) {
var cal = Calendar(identifier: .gregorian)
cal.timeZone = Calendar.current.timeZone
self.gregDate = cal.date(from: DateComponents(year: date.year, month: date.month, day: date.day, hour: includeTime ? date.hour : 0, minute: includeTime ? date.minute : 0, second: includeTime ? date.second : 0))!
let components = DateComponents(year: date.year, month: date.month, day: date.day, hour: includeTime ? date.hour : 0, minute: includeTime ? date.minute : 0, second: includeTime ? date.second : 0)
self.gregDate = cal.date(from: components)!

var hebCal = Calendar(identifier: .hebrew)
hebCal.timeZone = Calendar.current.timeZone

self.year = hebCal.component(.year, from: gregDate)
self.isJewishLeapYear = JewishDate.isJewishLeapYear(year)
self.month = JewishMonth.fromSwiftCalMonth(month: hebCal.component(.month, from: gregDate), isLeapYear: self.isJewishLeapYear)

self.day = hebCal.component(.day, from: gregDate)
self.dow = DayOfWeek(rawValue: Calendar.current.dateComponents([.weekday], from: gregDate).weekday!)!
}
Expand All @@ -36,7 +38,6 @@ public class JewishDate: Comparable {
var hebCal = Calendar(identifier: .hebrew)
hebCal.timeZone = Calendar.current.timeZone


let gregDate = hebCal.date(from: DateComponents(year: year, month: month.toSwiftCalMonth(JewishDate.isJewishLeapYear(year)), day: day))!
self.init(date: gregDate)
}
Expand Down
16 changes: 14 additions & 2 deletions Tests/KosherSwiftTests/KosherSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ final class KosherSwiftTests: XCTestCase {
XCTAssertEqual(jewishCalendar.moladDate.molad.minutes, 1)
XCTAssertEqual(jewishCalendar.moladDate.molad.chalakim, 3)

let moladFromKosherJava = Date(timeIntervalSince1970: 1702402813.0)//had to go up or down a few intervals to make it work
XCTAssertEqual(jewishCalendar.moladDate.gregDate, moladFromKosherJava)
let moladFromKosherJava = Date(timeIntervalSince1970: 1702402813.0) //had to go up or down a few intervals to make it work
let g = jewishCalendar.moladDate.gregDate
XCTAssertEqual(g.withAdded(hours: !Calendar.current.timeZone.isDaylightSavingTime(for: g) ? -1 : 0)!, moladFromKosherJava)
}


Expand Down Expand Up @@ -390,6 +391,17 @@ final class KosherSwiftTests: XCTestCase {
checkTimeEquals(cal.candleLighting(), 17, 40)
}

func testRoshChodeshAdar() {
let cal = JewishCalendar(date: Date(year: 2024, month: 3, day: 10))
let roshChodeshFormatter = HebrewDateFormatter()
// XCTAssertEqual(.adar, cal.month)
XCTAssertEqual("Rosh Chodesh Adar II", roshChodeshFormatter.formatRoshChodesh(cal))

// let cal2 = JewishCalendar(date: Date(year: 2024, month: 3, day: 11))
// XCTAssertEqual(.adar2, cal2.month)
// XCTAssertEqual("Adar II", roshChodeshFormatter.formatMonth(cal2))
}

func testFastOfEsther() {
let cal = JewishCalendar(date: Date(year: 2024, month: 1, day: 23), isInIsrael: false)
XCTAssert(!cal.isFastOfEsther)
Expand Down

0 comments on commit 9dce266

Please sign in to comment.