Java
Bikram Sambat dates, conversion, formatting and parsing for Java 17 and newer, with no runtime dependency and a real JPMS module.
- The core is
io.github.sanamhub:nepdate-java, packageio.github.sanamhub.nepdate.java, moduleio.github.sanamhub.nepdate.java. - Tithi, public holidays and events are a separate artifact,
io.github.sanamhub:nepdate-java-patro. The core has none of that data. - The Kotlin port stays for Kotlin and Android; this one is for a classpath without the Kotlin standard library.
Install
Section titled “Install”dependencies { implementation("io.github.sanamhub:nepdate-java:1.0.0-rc.1") implementation("io.github.sanamhub:nepdate-java-patro:1.0.0-rc.1") // tithi, holidays, events}<dependency><groupId>io.github.sanamhub</groupId><artifactId>nepdate-java</artifactId><version>1.0.0-rc.1</version></dependency>Every file on Maven Central is signed by the release key
44ED6E4129D97536CAE086175B979A307721A17B. The artifacts are JPMS modules
io.github.sanamhub.nepdate.java and io.github.sanamhub.nepdate.java.patro.
Every clock method takes a ZoneId or a Clock, so nothing reads a hidden local zone. The
supported range is BS 1901-01-01 to 2199-12-30 (AD 1844-04-11 to 2143-04-15).
Quick start
Section titled “Quick start”import io.github.sanamhub.nepdate.java.NepaliDate;
NepaliDate date = NepaliDate.of(2081, 4, 15);date.toString(); // 2081/04/15date.toLocalDate(); // 2024-07-30date.toLongString(); // Shrawan 15, 2081date.toIsoString(); // 2081-04-15NepaliDate.parse("2081/04/15"); // the same dateArithmetic is explicit about the two cases a month can have. CLAMP uses the target month’s last
day, SPILL carries the extra days into the next month:
import io.github.sanamhub.nepdate.java.MonthOverflow;import io.github.sanamhub.nepdate.java.NepaliDate;
NepaliDate date = NepaliDate.of(2081, 4, 32);date.plusMonths(2); // 2081/06/30date.plusMonths(2, MonthOverflow.SPILL); // 2081/07/02date.plusDays(1000); // 2084/01/30Formatting and parsing have an English and a Nepali form, and both parsers have a non-throwing
Optional variant:
import io.github.sanamhub.nepdate.java.*;import java.util.Optional;
NepaliDate date = NepaliDate.of(2081, 4, 15);date.toLongString(LongDateOptions.DEFAULT.withWeekday(true)); // Tuesday, Shrawan 15, 2081date.format("MMMM d, yyyy", Language.NEPALI); // साउन १५, २०८१NepaliDate.parseLenient("15 Shrawan 2080"); // 2080/04/15Optional<NepaliDate> none = NepaliDate.tryParse("2080/05/40");Ranges, fiscal years and today
Section titled “Ranges, fiscal years and today”import io.github.sanamhub.nepdate.java.*;import java.time.Clock;import java.time.Instant;
NepaliDateRange month = NepaliDateRange.forMonth(2081, 4);month.length(); // 32month.workingDays(false).count(); // the working days of the monthNepaliDate.of(2081, 4, 15).fiscalYear().label(); // 2081/82
Clock clock = Clock.fixed(Instant.parse("2024-07-30T18:30:00Z"), NepaliDate.KATHMANDU);NepaliDate.today(clock); // 2081/04/16Tithi, holidays and events
Section titled “Tithi, holidays and events”import io.github.sanamhub.nepdate.java.NepaliDate;import io.github.sanamhub.nepdate.java.patro.*;
CalendarInfo day = Patro.info(NepaliDate.of(2081, 1, 1));day.tithiEn(); // Panchamiday.isPublicHoliday(); // trueday.eventsEn(); // [New Year, Mesh Sankranti, Bisket Jatra]Patro.coverage(); // 2077/01/01 - 2084/08/20info never throws: a date outside the coverage returns one shared empty CalendarInfo. The data
covers BS 2077-01-01 to 2084-08-20.
What each artifact exports
Section titled “What each artifact exports”| Artifact | Names |
|---|---|
nepdate-java |
NepaliDate, NepaliDateRange, FiscalYear, Month, Weekday, Language, DateOrder, Separator, MonthOverflow, Quarter, LongDateOptions, NepDateException, NepDateError |
nepdate-java-patro |
Named, CalendarInfo, Patro |
Reference
Section titled “Reference”| Topic | Where |
|---|---|
| Signatures, defaults and exceptions | docs/API.md |
| Benchmarks against the Kotlin port, C# NepDate and the Maven Central competitor | docs/benchmarks.md |
| What changed | CHANGELOG.md |
| Source | sanamhub/nepdate-java |