Skip to content

Swift

One SwiftPM package with two products: NepDate (conversion, formatting, parsing, arithmetic, fiscal year) and NepDatePatro (tithi, public holidays and events for BS 2077-01-01 to 2084-08-20). NepDatePatro depends on NepDate, never the reverse, so an app that only converts dates links no patro data.

Pure Swift in the Swift 6 language mode, every type Sendable, no dependencies. The core doesn’t need Foundation; Date interop compiles in where Foundation exists. Small enough for widget and watch extensions. Apple platforms, Linux and Windows are all built in CI.

Add the package to Package.swift. SwiftPM only picks a pre-release when the requirement names one:

.package(url: "https://github.com/sanamhub/nepdate-swift", exact: "0.1.0-beta.1")

Then depend on NepDate, and on NepDatePatro as well for tithi, holidays and events:

.product(name: "NepDate", package: "nepdate-swift"),
.product(name: "NepDatePatro", package: "nepdate-swift"),

The package is listed on the Swift Package Index.

Conversion, formatting and parsing, with no patro data linked:

import NepDate
do {
let date = try NepaliDate(year: 2081, month: 4, day: 15)
print(date.format("s"))
print(date.long(weekday: true))
print(try NepaliDate.parse("2081-04-15").description)
} catch {
print("error: \(error)")
}
import NepDate
import NepDatePatro
let date = (try? NepaliDate(year: 2081, month: 1, day: 1)) ?? .min
let info = date.calendarInfo
print(info.tithi?.english ?? "no tithi")
for event in info.events {
print(event.english)
}

Both blocks are the repository’s Examples programs, so CI builds and runs them.

Topic Where
Every public symbol docs/API.md
Speed and allocations against the other Swift libraries and C# NepDate docs/benchmarks.md
What changed CHANGELOG.md
Source sanamhub/nepdate-swift