nepali_utils 2.0.0+4

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

Nepali Utilities for Dart #

Pub licence

A pure dart package with collection of Nepali Utilities like Date converter, Date formatter, DateTime, Nepali Number, Nepali Unicode, Nepali Moments and many more.

Package Includes #

  • NepaliDateTime
  • DateConversion
  • NepaliDateFormat
  • NepaliNumberFormat
  • NepaliUnicode
  • NepaliMoment
  • many yet to come

Nepali Date Time #

The class is similar to dart:core's DateTime class, except that, this works with Bikram Sambat.

NepaliDateTime gorkhaEarthQuake = NepaliDateTime.parse('2072-01-12T11:56:25');
print(gorkhaEarthQuake.year); // 2072

NepaliDateTime currentTime = NepaliDateTime.now();
print(currentTime.toIso8601String()); //2076-02-01T11:25:46.490980
print(gorkhaEarthQuake.mergeTime(10, 20, 30));
// 2072-01-12 10:20:30.000

Date Conversion #

Converts dates from AD to BS and vice versa. Note Since v2.x.x DateConverter has been integrated into NepaliDateTime class.

NepaliDateTime nt =
      NepaliDateTime.fromDateTime(DateTime(2019, 8, 03, 14, 30, 15));
print('In BS = $nt'); //2076-04-18 14:30:15.000
DateTime dt = nt.toDateTime(); //2019-08-03 14:30:15.000
print('In AD = $dt');

Nepali Date Formatter #

Formats NepaliDateTime into desired format. Formats NepaliDateTime into desired format.

Constructor table for quick formatting:

ConstructorResult
d18
ESat
EEEESaturday
LLLShr
LLLLShrawan
M4
Md4/18
MEdSat, 4/18
MMMShr
MMMdShr 18
MMMEdSaturday, Shr 18
MMMMShrawan
MMMMdShrawan 18
MMMMEEEEdSaturday, Shrawan 18
QQQQ2
QQQQ2nd quarter
y2076
yM2076/04
yMd2076/04/18
yMEdSat, 2076/04/18
yMMMShr 2076
yMMMdShr 18, 2076
yMMMEdSat, Shr 18, 2076
yMMMMMShrawan 2076
yMMMMdShrawan 18, 2076
yMMMMEEEEdSaturday, Shrawan 18, 2076
yQQQQ2 2076
yQQQQ2nd quarter 2076
H21
Hm21:04
Hms21:17:56
j9 PM
jm9:17 PM
jms9:17:56 PM
m9
ms9:17
s56

Example: #

var date1 = NepaliDateFormat.MEd();
var date2 = NepaliDateFormat.MMMMEEEEd();
var date3 = NepaliDateFormat.jms();

print(date1.format(gorkhaEarthQuake)); // Sat, 1/12 
print(date2.format(gorkhaEarthQuake)); // Saturday, Baisakh 18
print(date3.format(gorkhaEarthQuake)); // 11:56:00 AM

Formats can also be specified with a pattern string.

SymbolMeaningPresentationExample (en / np)
Gera designator(Text)BS / बि सं
GGera designator(Text)B.S. / बि.सं.
GGGera designator(Text)Bikram Sambat / बिक्रम संबत
yyear(Number)1996 / १९९६
yyyear(Number)96 / ९६
yyyyyear(Number)1996 / १९९६
Qquarter(Text)3
QQquarter(Text)03
QQQquarter(Text)Q3
QQQQquarter(Text)3rd quarter
Mmonth in year(Text & Number)1 / १
MMmonth in year(Text & Number)01 / ०१
MMMmonth in year(Text & Number)Bai / बै
MMMMmonth in year(Text & Number)Baishakh / बैशाख
dday in month(Number)9 / ९
ddday in month(Number)09 / ०९
Eday of week(Text)M / सो
EEday of week(Text)Mon / सोम
EEEday of week(Text)Monday / सोमबार
aam/pm marker(Text)pm / बेलुकी
aaam/pm marker(Text)PM / बेलुकी
hhour in am/pm(1~12)(Number)2 / २
hhhour in am/pm(1~12)(Number)02 / ०२
Hhour in day (0~23)(Number)14 / १४
HHhour in day (0~23)(Number)14 / १४
mminute in hour(Number)3 / ३
mmminute in hour(Number)03 / ०३
ssecond in minute(Number)55 / ५५
ssecond in minute(Number)55 / ५५
Sfractional second(Number)978 / ९७८
'escape for text(Delimiter)'Date='
''single quote(Literal)'o''clock'

Example: #

var date1 = NepaliDateFormat("yyyy.MM.dd G 'at' HH:mm:ss");
var date2 = NepaliDateFormat("EEE, MMM d, ''yy");
var date3 = NepaliDateFormat("h:mm a");
var date4 = NepaliDateFormat("hh 'o''clock' aa");
var date5 = NepaliDateFormat("yyyy.MMMM.dd GGG hh:mm a");

print(date1.format(gorkhaEarthQuake)); // 2072.01.12 BS at 11:56:25
print(date2.format(gorkhaEarthQuake)); // Saturday, Bai 12, '72
print(date3.format(gorkhaEarthQuake)); // 11:56 am
print(date4.format(gorkhaEarthQuake)); // 11 o'clock AM
print(date5.format(gorkhaEarthQuake)); // 2072.Baishakh.12 Bikram Sambat 11:56 am

Note: Always wrap pattern string in double quote (").

Nepali Number #

Converts English numbers into Nepali number literals.

var currencyFormat = NepaliNumberFormat(
    symbol: 'Rs.',
);
var commaSeparated = NepaliNumberFormat(
    decimalDigits: 2,
);
var inWords = NepaliNumberFormat(
    inWords: true,
    language: Language.NEPALI,
);
var currencyInWords = NepaliNumberFormat(
    inWords: true,
    language: Language.NEPALI,
    isMonetory: true,
    decimalDigits: 2,
);
print('123456 -> ${currencyFormat.format(123456)}');
// 123456 -> 1,23,456

print('123456789.6548 -> ${commaSeparated.format(123456789.6548)}');
// 123456789.6548 -> 12,34,56,789.65

print('123456 -> ${inWords.format(123456)}');
// 123456 -> 1 lakh 23 thousand 4 hundred 56

print('123456789.6548 -> ${currencyInWords.format(123456789.6548)}');
// 123456789.6548 -> १२ करोड ३४ लाख ५६ हजार ७ सय ८९ रुपैया ६५ पैसा

Nepali Unicode #

Converts English literal (Roman Literals) into Nepali Unicode.

print(NepaliUnicode.convert("sayau' thu''gaa fUlakaa haamii, euTai maalaa nepaalii"));
print(NepaliUnicode.convert("saarwabhauma bhai failiekaa, mecii-mahaakaalii\n"));

// स​यौं थुँगा फूलका हामी, एउटै माला नेपाली
// सार्वभौम भै फैलिएका, मेची-महाकाली

If live conversion is required i.e. conversion as you type, then set live: true.

NepaliUnicode.convert(textFromTextField, live: true);

Nepali Moment #

Generates a fuzzy timestamp using dates provided.

print(NepaliMoment.fromBS(NepaliDateTime.parse('2076-03-22T08:41:14')));
// २२ दिन पछि

Here, the current DateTime is 2076-02-32 19:09:25 i.e. reference date

print(NepaliMoment.fromBS(NepaliDateTime.parse('2076-02-32T18:25:14'),
      referenceDate: NepaliDateTime.parse('2076-02-32T18:34:14')));
// ९ मिनेट पहिले

print(NepaliMoment.fromAD(DateTime.parse('2019-06-02T18:22:14'),
      referenceDate: DateTime.parse('2019-06-15T18:34:14')));
// १३ दिन पहिले

Example #

Find more detailed example here.

Contribute #

If you want to contribute to the package, please feel free to submit issues or PR at Github Repo.

Also show some love by staring the repo ⭐, if you like the package.

License #

Copyright (c) 2019 Sarbagya Dhaubanjar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2.0.0+4 #

  • FIXED Issue with comma formatting in NepaliNumberFormat.

2.0.0+2 #

  • ADDED mergeTime method 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 about using newer APIs.

1.1.0+2 #

  • ADDED NepaliMoment class.

1.1.0 #

  • ADDED NepaliUnicode class.
  • Updated Dart Constraint to >=2.2.2 <3.0.0.

1.0.1 #

  • Fixed Wrong current datetime retrieval.

1.0.0+3 #

  • formatWithComma boolean argument added to from & fromString methods of NepaliNumber.

1.0.0+1 #

  • Added Example

1.0.0 #

Initial Version with

  • NepaliDateTime
  • DateConverter
  • NepaliDateFormatter
  • NepaliNumber

example/README.md

Nepali Utilities Example #

Nepali Date Time #

The class is similar to dart:core's DateTime class, except that, this works with Bikram Sambat.

NepaliDateTime gorkhaEarthQuake = NepaliDateTime.parse('2072-01-12T11:56:25');
print(gorkhaEarthQuake.year); // 2072

NepaliDateTime currentTime = NepaliDateTime.now();
print(currentTime.toIso8601String()); // 2076-02-01T11:25:46.490980

Date Converter #

Converts dates from AD to BS and vice versa.

NepaliDateTime nepaliDate = DateConverter.toBS(DateTime(2019, 5, 14));
print(nepaliDate); // 2076-01-31 00:00:00.000

DateTime englishDate = DateConverter.toAD(nepaliDate);
print(englishDate); // 2019-05-14 00:00:00.000

Nepali Date Formatter #

Formats NepaliDateTime into desired format.

var date1 = NepaliDateFormat.MEd();
var date2 = NepaliDateFormat.MMMMEEEEd();
var date3 = NepaliDateFormat.jms();

print(date1.format(gorkhaEarthQuake)); // Sat, 1/12 
print(date2.format(gorkhaEarthQuake)); // Saturday, Baisakh 18
print(date3.format(gorkhaEarthQuake)); // 11:56:00 AM
var date1 = NepaliDateFormat("yyyy.MM.dd G 'at' HH:mm:ss");
var date2 = NepaliDateFormat("EEE, MMM d, ''yy");
var date3 = NepaliDateFormat("h:mm a");
var date4 = NepaliDateFormat("hh 'o''clock' aa");
var date5 = NepaliDateFormat("yyyy.MMMM.dd GGG hh:mm a");

print(date1.format(gorkhaEarthQuake)); // 2072.01.12 BS at 11:56:25
print(date2.format(gorkhaEarthQuake)); // Saturday, Bai 12, '72
print(date3.format(gorkhaEarthQuake)); // 11:56 am
print(date4.format(gorkhaEarthQuake)); // 11 o'clock AM
print(date5.format(gorkhaEarthQuake)); // 2072.Baishakh.12 Bikram Sambat 11:56 am

Nepali Number #

Converts English numbers into Nepali number literals.

var currencyFormat = NepaliNumberFormat(
    symbol: 'Rs.',
);
var commaSeparated = NepaliNumberFormat(
    decimalDigits: 2,
);
var inWords = NepaliNumberFormat(
    inWords: true,
    language: Language.NEPALI,
);
var currencyInWords = NepaliNumberFormat(
    inWords: true,
    language: Language.NEPALI,
    isMonetory: true,
);

print('123456 -> ${currencyFormat.format(123456)}');
print('123456789.6548 -> ${commaSeparated.format(123456789.6548)}');
print('123456 -> ${inWords.format(123456)}');
print('123456789.6548 -> ${currencyInWords.format(123456789.6548)}');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  nepali_utils: ^2.0.0+4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:nepali_utils/nepali_utils.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
65
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on Oct 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:nepali_utils/nepali_utils.dart.

Health issues and suggestions

Document public APIs. (-0.29 points)

81 out of 83 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/nepali_number_format.dart. (-1 points)

Analysis of lib/src/nepali_number_format.dart reported 2 hints:

line 109 col 7: DO use curly braces for all flow control structures.

line 111 col 7: DO use curly braces for all flow control structures.

Format bin/main.dart.

Run dartfmt to format bin/main.dart.

Format lib/nepali_utils.dart.

Run dartfmt to format lib/nepali_utils.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0