Repository: jama5262/jiffy

Issue:
DayOfYear in bengali throws FormatException
**Describe the bug**

In the bengali (bn) locale, calling  .dayOfYear will throw.

```
Unhandled exception:
FormatException: Invalid radix-10 number (at character 1)
৩২৯
```

In Sentry the tokens are represented as `٣٣١`. Not sure where the difference comes from. edit: these are just numbers for the actual dayOfYear value.

**How to reproduce the bug**

edit: I thought it was only certain days, but it is any day.

```
    final date = Jiffy.parseFromDateTime(DateTime(2023, 11, 27));
    print(date.dayOfYear);
```

**What is the expected behavior**

The day of the year in the respective locale is returned

**Additional information**

I'll reach out to my own localization team for some more info as I don't speak any Bengali. The bug has little prio for me atm as it won't be relevant after today to fix for almost a year.

I'll dig into the code a little bit and the translations to see if I can fix it myself, but that might take a bit.



Discussion: Might be related to [103](https://github.com/jama5262/jiffy/issues/103).

After some experimenting I think it also throws in other non roman locales
Interesting bug, will take a look 👍 
I think I’ve figured out the issue 😓.

The bug was that Jiffy was failing to parse Bengali number symbols `[০১২৩৪৫৬৭৮৯]`.

For example, the day of the year might return `৭৮` (78), but Jiffy immediately tries to parse it as an integer. However, it fails because the digits are in Bengali, not standard numerals.

To fix this, we’ll use the [NumberFormat](https://pub.dev/documentation/intl/latest/intl/NumberFormat-class.html) class from the Intl package. Since it's locale-aware, it can correctly convert Bengali number symbols back into standard integers.

```dart
int quarterOfYear(DateTime dateTime, Locale locale) {
    return _toInt(DateFormat('Q', locale.code).format(dateTime), locale);
}

int dayOfYear(DateTime dateTime, Locale locale) {
  return _toInt(DateFormat('D', locale.code).format(dateTime), locale);
}

int _toInt(String localeNumber, Locale locale) {
    return NumberFormat.decimalPattern(locale.code).parse(localeNumber).toInt();
}
```

Will open a PR to fix this, thanks for you contribution 👍 


Fix patch:
diff --git a/lib/src/getter.dart b/lib/src/getter.dart
index 52f55a3..25a9203 100644
--- a/lib/src/getter.dart
+++ b/lib/src/getter.dart
@@ -59,11 +59,11 @@ class Getter {
   int month(DateTime dateTime) => dateTime.month;
 
   int quarterOfYear(DateTime dateTime, Locale locale) {
-    return int.parse(DateFormat('Q', locale.code).format(dateTime));
+    return _toInt(DateFormat('Q', locale.code).format(dateTime), locale);
   }
 
   int dayOfYear(DateTime dateTime, Locale locale) {
-    return int.parse(DateFormat('D', locale.code).format(dateTime));
+    return _toInt(DateFormat('D', locale.code).format(dateTime), locale);
   }
 
   int year(DateTime dateTime) => dateTime.year;
@@ -74,6 +74,10 @@ class Getter {
     return result;
   }
 
+  int _toInt(String localeNumber, Locale locale) {
+    return NumberFormat.decimalPattern(locale.code).parse(localeNumber).toInt();
+  }
+
   static final List<int> daysInMonthArray = List.from(
       [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
       growable: false);


Test patch:
diff --git a/test/src/getter_test.dart b/test/src/getter_test.dart
index 881c89b..ac92cb5 100644
--- a/test/src/getter_test.dart
+++ b/test/src/getter_test.dart
@@ -165,6 +165,20 @@ void main() {
       });
     }
 
+    test('Should successfully get day of year for non-standard number symbols',
+        () async {
+      // Setup
+      await Jiffy.setLocale('bn');
+      final newLocale = Jiffy.now().locale;
+
+      // Execute
+      final actualDayOfYear =
+          underTest.dayOfYear(DateTime(1997, 9, 23), newLocale);
+
+      // Verify
+      expect(actualDayOfYear, 266);
+    });
+
     for (var testData in weekOfYearTestData()) {
       test('Should successfully get week of year', () {
         // Setup
@@ -190,6 +204,20 @@ void main() {
         expect(actualQuarterOfYear, testData['expectedQuarterOfYear']);
       });
     }
+
+    test('Should successfully get quarter for non-standard number symbols',
+        () async {
+      // Setup
+      await Jiffy.setLocale('bn');
+      final newLocale = Jiffy.now().locale;
+
+      // Execute
+      final actualDayOfYear =
+          underTest.quarterOfYear(DateTime(2022, 4, 1), newLocale);
+
+      // Verify
+      expect(actualDayOfYear, 2);
+    });
   });
 
   for (var testData in daysInMonthTestData()) {