Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions example/shamsi_date_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ void main() {

print(format1Af(j1)); // prints: پنج شنبه 21 جدی 91

// Finglish example:
String format1Fn(Jalali d) {
final f = d.formatter;

return '${f.wNFn} ${f.d} ${f.mNFn} ${f.yy}';
}

print(format1Fn(j1)); // print: Panjshanbeh 21 Dey 91

// example two:
String format2(Date d) {
final f = d.formatter;
Expand Down
37 changes: 37 additions & 0 deletions lib/src/jalali/jalali_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ class JalaliFormatter extends DateFormatter {
'اسفند',
];

/// Jalali month names in Finglish
static const List<String> _monthNamesFinglish = [
'Farvardin',
'Ordibehesht',
'Khordad',
'Tir',
'Mordad',
'Shahrivar',
'Mehr',
'Aban',
'Azar',
'Dey',
'Bahman',
'Esfand',
];

/// Jalali Month Names in Afghanistan
static const List<String> _monthNamesAfghanistan = [
'حمل',
Expand Down Expand Up @@ -53,12 +69,28 @@ class JalaliFormatter extends DateFormatter {
'جمعه',
];

/// Jalali week day names in Finglish
static const List<String> _weekDayNamesFinglish = [
'Shanbeh',
'Yekshanbeh',
'Doshanbeh',
'Seshanbeh',
'Chaharshanbeh',
'Panjshanbeh',
'Jomeh',
];

/// Jalali month name
@override
String get mN {
return _monthNames[date.month - 1];
}

/// Jalali month names in Finglish
String get mNFn {
return _monthNamesFinglish[date.month - 1];
}

/// Jalali month name in Afghanistan
String get mNAf {
return _monthNamesAfghanistan[date.month - 1];
Expand All @@ -70,6 +102,11 @@ class JalaliFormatter extends DateFormatter {
return _weekDayNames[date.weekDay - 1];
}

/// Jalali week day name in Finglish
String get wNFn {
return _weekDayNamesFinglish[date.weekDay - 1];
}

/// Default date Seperator = `/`
@override
String get sep => '/';
Expand Down
17 changes: 17 additions & 0 deletions test/shamsi_date_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,23 @@ void main() {
expect(f3.wN, 'جمعه');
});

test('Jalali.formatter.mNFn', () {
final d1 = Jalali(1404, 4, 22);
final f1 = d1.formatter;
expect(f1.mNFn, 'Tir');
expect(f1.wNFn, 'Yekshanbeh');

final d2 = Jalali(1404, 6, 21);
final f2 = d2.formatter;
expect(f2.mNFn, 'Shahrivar');
expect(f2.wNFn, 'Jomeh');

final d3 = Jalali(1404, 12, 2);
final f3 = d3.formatter;
expect(f3.mNFn, 'Esfand');
expect(f3.wNFn, 'Shanbeh');
});

test('Jalali.formatter.mNAf', () {
final j1 = Jalali(1397, 1, 3);
final f1 = j1.formatter;
Expand Down