Skip to content

Dart

Bikram Sambat dates, conversion, formatting and parsing for Dart 3.6 and newer, and for Flutter on every platform. Pure Dart with no dependencies, including on the web.

  • You import 'package:nepdate/nepdate.dart'.
  • Tithi, public holidays and events are a separate package, nepdate_patro (import 'package:nepdate_patro/nepdate_patro.dart'). The core has none of that data.
Terminal window
dart pub add nepdate

dart pub add nepdate:1.0.0-rc.1 pins this pre-release; dart pub add nepdate_patro:1.0.0-rc.1 adds the patro.

import 'package:nepdate/nepdate.dart';
final d = NepaliDate.fromBs(2080, 5, 15);
d.toString(); // 2080/05/15
d.toDateTime(); // 2023-09-01 00:00:00.000Z
d.toLongString(weekday: true, lang: Lang.ne); // शुक्रवार, भदौ १५, २०८०
NepaliDate.parse('2080/05/15') == d; // true

Arithmetic stays on the BS calendar, so month lengths come from the shared data rather than from the Gregorian calendar:

final d = NepaliDate.fromBs(2080, 5, 15);
d.addDays(1000); // 2083/02/14
d.addMonths(13); // 2081/06/15
d.fiscalYear.label(); // 2080/81
Terminal window
dart pub add nepdate_patro
import 'package:nepdate/nepdate.dart';
import 'package:nepdate_patro/nepdate_patro.dart';
final day = info(NepaliDate.fromBs(2080, 5, 15));
day.isPublicHoliday; // true
day.tithi?.english; // Dwitiya
day.events.map((e) => e.english).toList(); // [Saparu (Gaijatra) (Kathmandu Holiday), Ropain Jatra]
coverage().start; // 2077/01/01

info never throws: a date outside the coverage returns one shared empty CalendarInfo. The data covers BS 2077-01-01 to 2084-08-20.

Package Names
nepdate NepaliDate, NepaliDateRange, FiscalYear, DateDiff, Lang, Month, Weekday, DateOrder, Separator, MonthOverflow, Quarter, ErrorKind, NepDateException
nepdate_patro Named, CalendarInfo, info, coverage, publicHolidays
Topic Where
Signatures, defaults and exceptions docs/API.md
Benchmarks against the pub.dev competitor and C# NepDate docs/benchmarks.md
What changed CHANGELOG.md
Source sanamhub/nepdate-dart