nepali_utils 4.0.0
nepali_utils: ^4.0.0 copied to clipboard
Nepali utilities for Dart: Bikram Sambat dates, Nepali numbers, Unicode/Preeti conversion, relative time, units, and phone validation.
4.0.0 #
Breaking Changes
-
Requires Dart 3.13 or later. Rewritten with modern Dart: primary constructors, dot shorthands, records & patterns, extension types and class modifiers.
-
NepaliDateTimeis now instant based, exactly likeDateTime:- It stores
microsecondsSinceEpochand presents fields in local time, UTC (NepaliDateTime.utc) or Nepal Time (NepaliDateTime.nepal,toNepalTime()). DateTime.toNepaliDateTime()keeps the instant and the time zone (it no longer shifts to Nepal Time). UsetoNepaliDateTime().toNepalTime()for Nepal Time.NepaliDateTime.now()returns local time, likeDateTime.now(). UseNepaliDateTime.nepalNow()for the current time in Nepal.toDateTime()returns the same instant (UTC values give a UTCDateTime).toUtc()now works,toLocal()converts to local time, andtimeZoneOffset/timeZoneNamereport the real zone.- Components are normalised like
DateTime, e.g.NepaliDateTime(2080, 1, 35)is2080-02-04, and dates outside 1969-2250 BS throw aRangeError. ==andhashCodecompare the instant and the time zone (previously identity).difference,isBefore,isAfter,isAtSameMomentAsandcompareToaccept anyDateTime.parsefollowsDateTime.parse: values withZor an offset are UTC, except+05:45which gives Nepal Time.NepaliDateTimeis now afinal class, and its constructors are factories.
- It stores
-
NepaliDateFormatnow followspackage:intl'sDateFormatexactly:-
Is now a
final classand accepts anyDateTimeinformat, keeping its time zone. -
Named constructors use intl's skeletons: the
enlayouts for English and thenelayouts for Nepali. A skeleton name passed to the default constructor (NepaliDateFormat('yMd')) is resolved the same way.Constructor 3.x 4.0 English 4.0 Nepali yM2076/088/2076२०७६-०८yMd2076/08/058/5/2076२०७६-०८-०५yMEdThu, 2076/08/05Thu, 8/5/2076२०७६-०८-०५, बिहिyMMMd(Nepali)मं ५, २०७६२०७६ मं ५j,jm,jms(Nepali)बेलुकी ९:०४२१:०४(24-hour)H909०९Like intl, English time skeletons (
j,jm,jms, ...) put a narrow no-break space () before AM/PM. -
Pattern letters follow intl:
Pattern 3.x 4.0 E/EE/EEET/Thu/ThursdayThu(all three)EEEE/EEEEEEEEE(printed literally)Thursday/TG/GG/GGGBS/B.S./Bikram SambatBS(all three);GGGGisBikram Sambata/aa(English)pm/PMPMMMMMMMarga(colloquial)M(narrow); the colloquial name is nowMMMMMMS/SS1/12123(at least 3 digits)QQQ/QQQQ(Nepali)Q3/3rd quarterतेस्रो त्रैमासिक;Qdigits are Devanagari -
Fixed
hfor midnight (12instead of0) andhhzero padding between 1 PM and 9 PM. -
Fixed the patterns of
NepaliDateFormat.Hm(HH:mm),.m(m) and.ms(mm:ss). -
The skeletons honour the default language set through
NepaliUtils.
-
-
Removed the unreleased
toNepaliDateTimeFromInstant(); usetoNepaliDateTime().toNepalTime(). -
The default language API now works like intl's
Intl.defaultLocaleandIntl.withLocale.NepaliUtilsonly has static members and can't be instantiated:NepaliUtils(language)→NepaliUtils.defaultLanguage = language.NepaliUtils().language→NepaliUtils.currentLanguage.- Formatters read the language when they are created, so
withLanguageapplies to formatters created inside it.
-
NepaliNumberFormatnow followspackage:intl'sNumberFormatand is an immutablefinal class:3.x 4.0 NepaliNumberFormat()NepaliNumberFormat.decimalPattern()(up to 3 fraction digits), orNepaliNumberFormat([pattern])NepaliNumberFormat(decimalDigits: 2)NepaliNumberFormat.decimalPatternDigits(decimalDigits: 2)isMonetory: true, symbol: 'Rs.'NepaliNumberFormat.simpleCurrency()(Rs. 1,234.00) or.currency(symbol: 'Rs.')symbolOnLeft,spaceBetweenAmountAndSymbolcurrency(customPattern: '#,##,##0.00 ¤')inWords: trueNepaliNumberFormat.words(), which now gives real words;words(useDigits: true)for the old1 lakh 23 thousandstyleinWords: true, isMonetory: trueNepaliNumberFormat.words(currency: true)delimiter: ''copyWith(groupSeparator: '')includeDecimalIfZero: falsecopyWith(includeDecimalIfZero: false)format<T>(T? number);nullgave''format(Object number);nullis a compile error- The currency patterns are those of intl's
nelocale, with a no-break space after the symbol. - Numbers are rounded half away from zero instead of truncated:
2.999with 2 digits is3.00, not2.99. - In Nepali, rupees is spelled
रुपैयाँ.
- The currency patterns are those of intl's
-
NepaliMomentis now an immutable formatter (NepaliMoment(language:, style:, useWeeks:)) in the style of moment.js.fromBSandfromADremain as shorthands:- Fixed English phrases:
a few seconds ago,5 minutes ago,2 months agoandin 3 days(wasfew moment ago,5 minute ago,2 month agoand3 days from now). - The thresholds are moment.js's: e.g. 22 hours is
a day, 26 days isa month, and 320 days isa year. Previously 350 days could give12 months. - About an hour, a month or a year is now
an hour/एक घण्टा(wasabout an hour/लगभग एक घण्टा). - Removed the
showTodayparameter, which had no effect; usecalendarorformatUnit(0, .day, numeric: false).
- Fixed English phrases:
-
NepaliUnicodeis now an immutableConverter<String, String>:3.x 4.0 NepaliUnicode.convert(text)const NepaliUnicode().convert(text)NepaliUnicode.convert(text, live: true)const NepaliUnicode().convertLive(text), or justconvert: Devanagari followed by romanized text is joined either way- The default
classicstyle keeps the 3.x rules, with these fixes: zero width spaces no longer leak into the output (sayaugaveसयौ),amno longer gives य (kamalwasकयल्),chhgives छ (chhoraawasछ्ोरा),gygives ज्ञ (gyaanwasज्ञ्ान्),nghgives ंह (singhawasसिहं), any whitespace (not only a space) drops a halant, andkchyno longer gives क्ष. - Text inside
{}is now kept as it is, so a literal{must be escaped as{{}.
- The default
New
- Conversions between Nepali units with
NepaliArea(ropani-aana-paisa-daam, bigha-kattha-dhur, square feet/metres, acres, hectares),NepaliWeight(tola-lal, dharni-ser-pau-chhatak, grams) andNepaliVolume(muri-pathi-mana-muthi, litres). Each converts withto(unit), splits into mixed units (ropaniParts), formats (2-3-1-0/२ रोपनी ३ आना १ पैसा), parses ASCII or Devanagari input and supports arithmetic and comparison. NepaliPhoneNumbervalidates and parses Nepali mobile and landline numbers (ASCII or Devanagari digits, with or without+977), reports the mobile operator (per NTA's National Numbering Allocation Plan, 2079) or the landline area code and district, formats them as national, international or E.164, and finds them in text withfindAllandreplaceAll.NepaliUnicodegains:- Styles:
NepaliUnicode(style: .google)for Google Input Tools style romanization (nepaal→नेपाल,~for a halant), and Madan Puraskar Pustakalaya's keyboard layouts.mppRomanizedand.mppTraditional. toRoman, the reverse conversion (नेपाली→nepaalii), which round-trips throughconvert.{English}escapes (mero naam {Sarbagya} ho→मेरो नाम Sarbagya हो) andnepaliDigits: false.- Stream support:
stream.transform(const NepaliUnicode()).
- Styles:
Preeti.toUnicodeandPreeti.fromUnicodeconvert legacy Preeti-font text (g]kfn↔नेपाल), reordering ि and the reph.Devanagarihelpers:isDevanagari,containsDevanagari,toNepaliDigits,toEnglishDigitsandaksharas(संस्कृति→[सं, स्कृ, ति]).NepaliMomentgains:formatDuration(3 days, orin 3 dayswithwithSuffix).formatUnit, likeIntl.RelativeTimeFormat:formatUnit(-1, .day)is1 day ago, and withnumeric: falseit isyesterday/हिजो.calendar:Today at 9:04 PM,Yesterday at …,Last Sunday at …, or the date /आज २१:०४,गएको आइतबार, २१:०४.- Short style (
3 hr. ago/३ घ. पहिले) and optional weeks (3 weeks ago).
NepaliNumberFormatgains what intl'sNumberFormathas:percentPattern,decimalPercentPattern,currency,simpleCurrency,compact(12.3L),compactLong(12.3 lakh),compactCurrencyandcompactSimpleCurrency. Compact formats use thousand, lakh, crore, arab and kharab.- Custom patterns:
NepaliNumberFormat('#,##0.00')for international grouping,%,‰,¤, quoted text and negative subpatterns (#,##0;(#,##0)). parseandtryParse, which accept ASCII and Devanagari digits.minimumIntegerDigits,minimumFractionDigits,maximumFractionDigitsand significant digits, set withcopyWith.
NepaliNumberFormatformats negative numbers, doubles such as1e21and1.5e-7,BigInts and numeric strings without losing digits. Doubles are rounded as written, so1.005rounds to1.01.NepaliNumberFormat.wordsspells numbers out (one lakh twenty-three thousand four hundred fifty-six/एक लाख तेइस हजार चार सय छपन्न). It also handles negative numbers, fractions and values beyond a sankha, and no longer shows zero groups (1 lakh 00 thousand 0 hundred 00).NepaliDateTime.utc,.nepal,.nepalNow,.fromMicrosecondsSinceEpoch,.fromMillisecondsSinceEpoch,copyWith,toNepalTime,isNepalTimeand weekday/month constants (NepaliDateTime.sunday,NepaliDateTime.baishakh, ...).NepaliDateTime.fromDateTimeis no longer deprecated.NepaliDateFormatgains what intl'sDateFormathas:- The pattern letters
L(standalone month),c(standalone weekday),D(day of year),K(hour 0-11),k(hour 1-24),z/v(time zone:NPT,UTC, or the local name;zzzzisNepal Time) andZ(+0545,GMT+05:45). intl leaves the time-zone letters empty. - The
EEEEE,jmv,jmz,jvandjzconstructors. - The skeleton constants (
NepaliDateFormat.YEAR_MONTH_DAY, ...). addPatternandadd_*()(e.g.NepaliDateFormat.yMd().add_jms()). These return a new formatter, becauseNepaliDateFormatis immutable.NepaliDateFormat()without a pattern usesyMMMMd jms.
- The pattern letters
Languageconverts to and from locales:languageCode,countryCode,localeName,toLanguageTag(),Language.parse,Language.tryParseandLanguage.fromLocale.NepaliUtils.withLanguage(language, () => ...)overrides the language for the code run inside the callback, including async work.NepaliUtils.currentLanguagereturns the language in effect.NepaliMoment.fromBSandfromADaccept alanguage.
Performance
- Conversion is constant time using a precomputed month index and pure integer Gregorian arithmetic (AD → BS ~16x faster,
weekday~500x faster than 3.x). - Formatting compiles the pattern once and converts digits directly.
NepaliUnicodeconverts in a single pass instead of ~170replaceAllpasses per character: linear instead of quadratic, e.g. 10,000 characters take 0.4 ms instead of 13.6 s.
3.0.8 #
- Fixed dates for year 2082 & 2093.
3.0.7 #
- Added
MMMMMsupport for NepaliDateFormat; alt version of months.
3.0.6 #
- Added support for
NepaliDateTimeup to 2250 BS.
3.0.5 #
- Same as [3.0.6]
3.0.4 #
- Fixes date time conversion for timezone other than Nepal.
3.0.3 #
- Adds english support for moment conversion.
3.0.1 #
- Fixed incorrect date conversion for the year 1970.
3.0.0 #
Breaking Changes
- Migrated to Null Safety
- Added support for
NepalitDateTimefrom 1970 BS to 2100 BS.
2.2.1 #
- Renamed
weekDaytoweekday.
2.2.0+2 #
- Improved Date Conversion Speed
2.2.0+1 #
- Added
weekDayproperty to NepaliDateTime.
2.2.0 #
- Default language for all the utility classes can be set as
NepaliUtils(language);. Breaking Changes languageproperty is now optional for utility classes.
2.1.0+5 #
fromDateTime()is deprecated. UsetoNepaliDateTime()exposed toDateTimeinstead.- Added
add(),substract(),format(),millisecondSinceEpoch,microsecondSinceEpochtoNepaliDateTime.
2.1.0+4 #
- Fixes in NepaliNumberFormat.
- Fixed lint warning.
2.1.0+1 #
- Added
totalDaysgetter for NepaliDateTime class.
2.1.0 #
- [Improvement] Code refactor.
- Added dart docs.
- Methods in NepaliNumberFormat are now generic and supports types
Stringandnum.
2.0.0+4 #
- FIXED Issue with comma formatting in
NepaliNumberFormat.
2.0.0+2 #
- ADDED
mergeTimemethod to NepaliDateTime.
2.0.0+1 #
BREAKING CHANGES
- DateConvertor is now integrated to NepaliDateTime class.
- NepaliNumber is renamed into NepaliNumberFormat.
- NepaliDateFormatter is renamed into NepaliDateFormat.
- FEATURE The package now supports from 2000 B.S. upto 2099 B.S.
- Preconfigured constructors are added for quick formatting in NepaliDateFormat class.
See ReadMe section to know about using newer APIs.
1.1.0+2 #
- ADDED
NepaliMomentclass.
1.1.0 #
- ADDED
NepaliUnicodeclass. - Updated Dart Constraint to
>=2.2.2 <3.0.0.
1.0.1 #
- Fixed Wrong current datetime retrieval.
1.0.0+3 #
formatWithCommaboolean argument added tofrom&fromStringmethods of NepaliNumber.
1.0.0+1 #
- Added Example
1.0.0 #
Initial Version with
- NepaliDateTime
- DateConverter
- NepaliDateFormatter
- NepaliNumber
