Repository: jama5262/jiffy

Issue:
Locale class clashes with namesake from material.dart
**Describe the bug**

Since version 6.4 the `Locale` class has been exported. However, it clashes with the `Locale` class from material.dart.

**How to reproduce the bug**

Create a Flutter project, import both material and jiffy (even as indirect dependency), try to use the `Locale` class: it uses the one from jiffy, which breaks all existing code relying on material's Locale.

**What is the expected behavior**

The Locale class should not be exported by default, or should have a different name, or should be converted to an extension function of material's Locale class.
 
**Screenshots**

All of these problems appeared after upgrading jiffy from 6.3 to 6.4:

<img width="836" alt="Image" src="https://github.com/user-attachments/assets/3170bd52-aab8-4fba-8251-be5aa52bb747" />




Discussion: @mauriziopinotti 

Can I see an example of the import on how you used it, maybe aliases could help, here's how to use it https://dart.dev/language/libraries#specifying-a-library-prefix

Can you also please share a snippet of your code plus a pub dev link to the material package you a talking about

So that i can replicate it myself
> [@mauriziopinotti](https://github.com/mauriziopinotti)
> 
> Can I see an example of the import on how you used it, maybe aliases could help, here's how to use it https://dart.dev/language/libraries#specifying-a-library-prefix
> 
> Can you also please share a snippet of your code plus a pub dev link to the material package you a talking about
> 
> So that i can replicate it myself

Aliases can help but I see it as a workaround as I need to modify every line that references material's `Locale` class, which is inconvenient. And, generally speaking, I think plugins' classes should not have the same name of framework classes to avoid confusion.


You can also do the following when importing Jiffy

```dart
import 'package:jiffy/jiffy.dart' as jiffy;

final j = jiffy.Jiffy.now();
```
> You can also do the following when importing Jiffy
> 
> import 'package:jiffy/jiffy.dart' as jiffy;
> 
> final j = jiffy.Jiffy.now();

I do not import Jiffy, it's a transitive dependency. I use `stream_chat_flutter` that depends on `jiffy` but having `jiffy` in the `pubspec.lock` is enough to confuse Flutter.
> Aliases can help but I see it as a workaround as I need to modify every line that references material's `Locale` class, which is inconvenient. And, generally speaking, I think plugins' classes should not have the same name of framework classes to avoid confusion.

You are right, yeah, let me update the Locale to JiffyLocale
Version [6.4.2](https://pub.dev/packages/jiffy/install) is out, please try and hopefully it fixes the issue

If not, please feel free to reopen this issue again
Thank you, confirmed fixed 🤝 

Fix patch:
diff --git a/README.md b/README.md
index 1f364ac..d716f0c 100644
--- a/README.md
+++ b/README.md
@@ -87,7 +87,7 @@ Jiffy.parse('1997/9/23')
 ## Locale Support
 ```dart
 // Get current locale code, by default it is en_us
-Jiffy.now().locale.code; // en_us
+Jiffy.now().localeCode; // en_US
 
 // Setting your preferred locale
 await Jiffy.setLocale('fr_ca');
diff --git a/doc/README.md b/doc/README.md
index c9a0555..d96eb73 100644
--- a/doc/README.md
+++ b/doc/README.md
@@ -712,11 +712,11 @@ jiffy1.from(jiffy2); // like a day ago, i think
 
 ## Getting the locale information
 ```dart
-final locale = Jiffy.now().locale; // Returns a jiffy locale object
-final localeCode = locale.code;
-final localeStartOfWeek = locale.startOfWeek;
-final localeCode = locale.ordinals;
-final localeCode = locale.relativeDateTime;
+final jiffy = Jiffy.now(); // Returns a jiffy locale object
+final localeCode = jiffy.localeCode;
+final localeStartOfWeek = jiffy.startOfWeek;
+final localeCode = jiffy.ordinals;
+final localeCode = jiffy.relativeDateTime;
 ```
 ## Getting a list of supported locales
 ```dart
diff --git a/lib/jiffy.dart b/lib/jiffy.dart
index c412795..9d75e73 100644
--- a/lib/jiffy.dart
+++ b/lib/jiffy.dart
@@ -5,7 +5,6 @@ library;
 
 export 'src/enums/unit.dart';
 export 'src/enums/start_of_week.dart';
-export 'src/locale/jiffy_locale.dart';
 export 'src/locale/ordinals.dart';
 export 'src/locale/relative_date_time.dart';
 export 'src/jiffy.dart';
diff --git a/lib/src/display.dart b/lib/src/display.dart
index ffb10ed..ec4e36a 100644
--- a/lib/src/display.dart
+++ b/lib/src/display.dart
@@ -2,7 +2,7 @@ import 'package:intl/intl.dart';
 
 import 'getter.dart';
 import 'enums/unit.dart';
-import 'locale/jiffy_locale.dart';
+import 'locale/locale.dart';
 import 'manipulator.dart';
 import 'query.dart';
 import 'utils/jiffy_exception.dart';
@@ -16,7 +16,7 @@ class Display {
 
   String formatToISO8601(DateTime dateTime) => dateTime.toIso8601String();
 
-  String format(DateTime dateTime, String pattern, JiffyLocale locale) {
+  String format(DateTime dateTime, String pattern, Locale locale) {
     if (pattern.trim().isEmpty) {
       throw JiffyException('The provided pattern for datetime `$dateTime` '
           'cannot be blank');
@@ -28,7 +28,7 @@ class Display {
   }
 
   String fromAsRelativeDateTime(DateTime firstDateTime, DateTime secondDateTime,
-      JiffyLocale locale, bool withPrefixAndSuffix) {
+      Locale locale, bool withPrefixAndSuffix) {
     final isFirstDateTimeSameOrAfterSecondDateTime = _query.isSameOrAfter(
         firstDateTime, secondDateTime, Unit.microsecond, locale.startOfWeek);
 
@@ -92,7 +92,7 @@ class Display {
   }
 
   String toAsRelativeDateTime(DateTime firstDateTime, DateTime secondDateTime,
-      JiffyLocale locale, bool withPrefixAndSuffix) {
+      Locale locale, bool withPrefixAndSuffix) {
     return fromAsRelativeDateTime(
         secondDateTime, firstDateTime, locale, withPrefixAndSuffix);
   }
diff --git a/lib/src/getter.dart b/lib/src/getter.dart
index 569b8b3..25a9203 100644
--- a/lib/src/getter.dart
+++ b/lib/src/getter.dart
@@ -1,7 +1,7 @@
 import 'package:intl/intl.dart';
 
 import 'enums/start_of_week.dart';
-import 'locale/jiffy_locale.dart';
+import 'locale/locale.dart';
 import 'query.dart';
 
 class Getter {
@@ -48,7 +48,7 @@ class Getter {
   int daysInMonth(DateTime dateTime) =>
       _daysInMonth(dateTime.year, dateTime.month);
 
-  int weekOfYear(DateTime dateTime, JiffyLocale locale) {
+  int weekOfYear(DateTime dateTime, Locale locale) {
     return ((dayOfYear(dateTime, locale) -
                 dayOfWeek(dateTime, locale.startOfWeek) +
                 10) /
@@ -58,11 +58,11 @@ class Getter {
 
   int month(DateTime dateTime) => dateTime.month;
 
-  int quarterOfYear(DateTime dateTime, JiffyLocale locale) {
+  int quarterOfYear(DateTime dateTime, Locale locale) {
     return _toInt(DateFormat('Q', locale.code).format(dateTime), locale);
   }
 
-  int dayOfYear(DateTime dateTime, JiffyLocale locale) {
+  int dayOfYear(DateTime dateTime, Locale locale) {
     return _toInt(DateFormat('D', locale.code).format(dateTime), locale);
   }
 
@@ -74,7 +74,7 @@ class Getter {
     return result;
   }
 
-  int _toInt(String localeNumber, JiffyLocale locale) {
+  int _toInt(String localeNumber, Locale locale) {
     return NumberFormat.decimalPattern(locale.code).parse(localeNumber).toInt();
   }
 
diff --git a/lib/src/jiffy.dart b/lib/src/jiffy.dart
index e9e1526..718940a 100644
--- a/lib/src/jiffy.dart
+++ b/lib/src/jiffy.dart
@@ -6,7 +6,7 @@ import './display.dart';
 import './enums/start_of_week.dart';
 import './enums/unit.dart';
 import './getter.dart';
-import './locale/jiffy_locale.dart';
+import './locale/locale.dart';
 import './manipulator.dart';
 import './parser.dart';
 import './query.dart';
@@ -29,7 +29,7 @@ class Jiffy {
   late final Query _query;
   late final Display _display;
 
-  late JiffyLocale _locale;
+  late Locale _locale;
   late final DateTime _dateTime;
 
   /// Sets the locale for this [Jiffy] instance based on the given [locale] string.
@@ -294,7 +294,7 @@ class Jiffy {
 
   void _initializeLocale() {
     var currentLocale = Intl.getCurrentLocale();
-    _locale = JiffyLocale(
+    _locale = Locale(
         code: currentLocale,
         startOfWeek: getStartOfWeek(currentLocale),
         ordinals: getOrdinals(currentLocale),
@@ -318,8 +318,17 @@ class Jiffy {
     }
   }
 
-  /// Returns the [JiffyLocale].
-  JiffyLocale get locale => _locale;
+  /// Returns the locale code
+  String get localeCode => _locale.code;
+
+  /// Returns the locale start of week
+  StartOfWeek get startOfWeek => _locale.startOfWeek;
+
+  /// Returns the locale ordinals
+  Ordinals get ordinals => _locale.ordinals;
+
+  /// Returns the locale relative date time
+  RelativeDateTime get relativeDateTime => _locale.relativeDateTime;
 
   /// Creates and returns a new [Jiffy] instance with the same date and time
   /// as the original instance.
@@ -387,7 +396,7 @@ class Jiffy {
   /// leap year.
   int get dayOfYear => _getter.dayOfYear(dateTime, _locale);
 
-  /// Returns the week number of the year based on the current [JiffyLocale]'s
+  /// Returns the week number of the year based on the current [Locale]'s
   /// defined start of the week.
   ///
   /// The week number ranges from 1 to 53, where week 1 is the first week
diff --git a/lib/src/locale/jiffy_locale.dart b/lib/src/locale/locale.dart
similarity index 96%
rename from lib/src/locale/jiffy_locale.dart
rename to lib/src/locale/locale.dart
index 71fa1ad..29d3706 100644
--- a/lib/src/locale/jiffy_locale.dart
+++ b/lib/src/locale/locale.dart
@@ -3,7 +3,7 @@ import 'package:jiffy/src/locale/ordinals.dart';
 import '../enums/start_of_week.dart';
 import 'relative_date_time.dart';
 
-class JiffyLocale {
+class Locale {
   /// Returns the locale code for this locale.
   ///
   /// The locale code is a string identifier that uniquely identifies a
@@ -27,7 +27,7 @@ class JiffyLocale {
   /// a specific locale.
   final RelativeDateTime relativeDateTime;
 
-  JiffyLocale({
+  Locale({
     required this.code,
     required this.ordinals,
     required this.startOfWeek,
diff --git a/lib/src/parser.dart b/lib/src/parser.dart
index 4c5a750..4e107b6 100644
--- a/lib/src/parser.dart
+++ b/lib/src/parser.dart
@@ -3,7 +3,7 @@ import 'package:jiffy/src/locale/ordinals.dart';
 
 import 'enums/unit.dart';
 import 'getter.dart';
-import 'locale/jiffy_locale.dart';
+import 'locale/locale.dart';
 import 'utils/jiffy_exception.dart';
 
 class Parser {
@@ -12,7 +12,7 @@ class Parser {
   Parser(this._getter);
 
   DateTime fromString(
-      String input, String? pattern, JiffyLocale locale, bool isUtc) {
+      String input, String? pattern, Locale locale, bool isUtc) {
     if (pattern != null) {
       if (pattern.trim().isEmpty) {
         throw JiffyException('The provided pattern for input `$input` cannot '


Test patch:
diff --git a/test/src/display_test.dart b/test/src/display_test.dart
index 179c485..8192258 100644
--- a/test/src/display_test.dart
+++ b/test/src/display_test.dart
@@ -1,23 +1,29 @@
 import 'package:jiffy/jiffy.dart';
 import 'package:jiffy/src/display.dart';
 import 'package:jiffy/src/getter.dart';
+import 'package:jiffy/src/locale/locale.dart';
 import 'package:jiffy/src/manipulator.dart';
 import 'package:jiffy/src/query.dart';
 import 'package:jiffy/src/utils/jiffy_exception.dart';
 import 'package:test/test.dart';
 
-void main() {
-  final getter = Getter();
-  final manipulator = Manipulator(getter);
-  final query = Query(getter, manipulator);
+final getter = Getter();
+final manipulator = Manipulator(getter);
+final query = Query(getter, manipulator);
 
-  final underTest = Display(getter, manipulator, query);
+final underTest = Display(getter, manipulator, query);
 
-  late JiffyLocale locale;
+late Locale locale;
 
+void main() {
   setUp(() async {
-    Jiffy.setLocale("en");
-    locale = Jiffy.now().locale;
+    Jiffy.setLocale("en_US");
+    final jiffy = Jiffy.now();
+    locale = Locale(
+        code: jiffy.localeCode,
+        ordinals: jiffy.ordinals,
+        startOfWeek: jiffy.startOfWeek,
+        relativeDateTime: jiffy.relativeDateTime);
   });
 
   test('Should successfully format datetime is iso when pattern not provided',
diff --git a/test/src/getter_test.dart b/test/src/getter_test.dart
index c8b6969..9f9ee76 100644
--- a/test/src/getter_test.dart
+++ b/test/src/getter_test.dart
@@ -1,15 +1,21 @@
 import 'package:jiffy/jiffy.dart';
 import 'package:jiffy/src/getter.dart';
+import 'package:jiffy/src/locale/locale.dart';
 import 'package:test/test.dart';
 
 final underTest = Getter();
 
-late JiffyLocale locale;
+late Locale locale;
 
 void main() {
   setUp(() async {
     Jiffy.setLocale("en_US");
-    locale = Jiffy.now().locale;
+    final jiffy = Jiffy.now();
+    locale = Locale(
+        code: jiffy.localeCode,
+        ordinals: jiffy.ordinals,
+        startOfWeek: jiffy.startOfWeek,
+        relativeDateTime: jiffy.relativeDateTime);
   });
 
   group('Test basic datetime getters', () {
@@ -169,7 +175,12 @@ void main() {
         () async {
       // Setup
       await Jiffy.setLocale('bn');
-      final newLocale = Jiffy.now().locale;
+      final jiffy = Jiffy.now();
+      final newLocale = Locale(
+          code: jiffy.localeCode,
+          ordinals: jiffy.ordinals,
+          startOfWeek: jiffy.startOfWeek,
+          relativeDateTime: jiffy.relativeDateTime);
 
       // Execute
       final actualDayOfYear =
@@ -183,7 +194,12 @@ void main() {
       test('Should successfully get week of year', () {
         // Setup
         Jiffy.setLocale(locale.code, startOfWeek: testData['startOfWeek']);
-        final newLocale = Jiffy.now().locale;
+        final jiffy = Jiffy.now();
+        final newLocale = Locale(
+            code: jiffy.localeCode,
+            ordinals: jiffy.ordinals,
+            startOfWeek: testData['startOfWeek'],
+            relativeDateTime: jiffy.relativeDateTime);
 
         // Execute
         final actualWeekOfYear =
@@ -209,7 +225,12 @@ void main() {
         () async {
       // Setup
       await Jiffy.setLocale('bn');
-      final newLocale = Jiffy.now().locale;
+      final jiffy = Jiffy.now();
+      final newLocale = Locale(
+          code: jiffy.localeCode,
+          ordinals: jiffy.ordinals,
+          startOfWeek: jiffy.startOfWeek,
+          relativeDateTime: jiffy.relativeDateTime);
 
       // Execute
       final actualDayOfYear =
diff --git a/test/src/jiffy_test.dart b/test/src/jiffy_test.dart
index 4ae04dc..74253ac 100644
--- a/test/src/jiffy_test.dart
+++ b/test/src/jiffy_test.dart
@@ -234,14 +234,16 @@ void main() {
       final expectedLocaleRelativeDateTime = JaRelativeDateTime();
 
       // Execute
-      final actualLocale = jiffy.locale;
+      final actualLocaleCode = jiffy.localeCode;
+      final actualStartOfWeek = jiffy.startOfWeek;
+      final actualOrdinals = jiffy.ordinals;
+      final actualRelativeDateTime = jiffy.relativeDateTime;
 
       // Verify
-      expect(actualLocale.code, expectedLocaleCode);
-      expect(actualLocale.startOfWeek, expectedLocaleStartOfWeek);
-      expect(actualLocale.ordinals, equals(expectedLocaleOrdinals));
-      expect(actualLocale.relativeDateTime,
-          equals(expectedLocaleRelativeDateTime));
+      expect(actualLocaleCode, expectedLocaleCode);
+      expect(actualStartOfWeek, expectedLocaleStartOfWeek);
+      expect(actualOrdinals, equals(expectedLocaleOrdinals));
+      expect(actualRelativeDateTime, equals(expectedLocaleRelativeDateTime));
     });
 
     test('Should successfully configure start of week', () async {
@@ -249,13 +251,13 @@ void main() {
       await Jiffy.setLocale('ja');
 
       // Verify default start of week before changing
-      expect(Jiffy.now().locale.startOfWeek, StartOfWeek.sunday);
+      expect(Jiffy.now().startOfWeek, StartOfWeek.sunday);
 
       // Execute
       await Jiffy.setLocale('ja', startOfWeek: StartOfWeek.monday);
 
       // Verify
-      expect(Jiffy.now().locale.startOfWeek, StartOfWeek.monday);
+      expect(Jiffy.now().startOfWeek, StartOfWeek.monday);
     });
 
     test('Should successfully configure ordinals', () async {
@@ -263,7 +265,7 @@ void main() {
       await Jiffy.setLocale('en_US');
 
       // Verify default ordinal before changing
-      expect(Jiffy.now().locale.ordinals,
+      expect(Jiffy.now().ordinals,
           Ordinals(first: 'st', second: 'nd', third: 'rd', nth: 'th'));
 
       // Execute
@@ -272,7 +274,7 @@ void main() {
       await Jiffy.setLocale('ja', ordinals: newOrdinal);
 
       // Verify
-      expect(Jiffy.now().locale.ordinals, newOrdinal);
+      expect(Jiffy.now().ordinals, newOrdinal);
     });
 
     test('Should successfully configure relative date time', () async {
@@ -280,15 +282,14 @@ void main() {
       await Jiffy.setLocale('ja');
 
       // Verify default relative date time before changing
-      expect(Jiffy.now().locale.relativeDateTime, JaRelativeDateTime());
+      expect(Jiffy.now().relativeDateTime, JaRelativeDateTime());
 
       // Execute
       await Jiffy.setLocale('ja',
           relativeDateTime: UpdatedJpRelativeDateTime());
 
       // Verify
-      expect(Jiffy.now().locale.relativeDateTime.aboutAMonth(1),
-          "some months ago");
+      expect(Jiffy.now().relativeDateTime.aboutAMonth(1), "some months ago");
     });
 
     group('Test available locales', () {
diff --git a/test/src/locale/relative_date_time_test.dart b/test/src/locale/relative_date_time_test.dart
index ade2132..8a44bd9 100644
--- a/test/src/locale/relative_date_time_test.dart
+++ b/test/src/locale/relative_date_time_test.dart
@@ -4,7 +4,7 @@ import 'package:jiffy/src/manipulator.dart';
 import 'package:jiffy/src/display.dart';
 import 'package:jiffy/src/enums/start_of_week.dart';
 import 'package:jiffy/src/getter.dart';
-import 'package:jiffy/src/locale/jiffy_locale.dart';
+import 'package:jiffy/src/locale/locale.dart';
 import 'package:jiffy/src/query.dart';
 
 import 'package:test/test.dart';
@@ -19,7 +19,7 @@ void main() {
     for (var testData in localesRelativeDateTimeTestData()) {
       test('Should successfully return correct relative date time', () {
         // Setup
-        final locale = JiffyLocale(
+        final locale = Locale(
             code: "en",
             ordinals:
                 Ordinals(first: "st", second: "nd", third: "rd", nth: "th"),
diff --git a/test/src/parser_test.dart b/test/src/parser_test.dart
index e9b85c6..221000a 100644
--- a/test/src/parser_test.dart
+++ b/test/src/parser_test.dart
@@ -1,18 +1,24 @@
 import 'package:jiffy/jiffy.dart';
 import 'package:jiffy/src/getter.dart';
+import 'package:jiffy/src/locale/locale.dart';
 import 'package:jiffy/src/parser.dart';
 import 'package:jiffy/src/utils/jiffy_exception.dart';
 import 'package:test/test.dart';
 
-void main() {
-  final getter = Getter();
-  final underTest = Parser(getter);
+final getter = Getter();
+final underTest = Parser(getter);
 
-  late JiffyLocale locale;
+late Locale locale;
 
+void main() {
   setUp(() async {
-    Jiffy.setLocale("en");
-    locale = Jiffy.now().locale;
+    Jiffy.setLocale("en_US");
+    final jiffy = Jiffy.now();
+    locale = Locale(
+        code: jiffy.localeCode,
+        ordinals: jiffy.ordinals,
+        startOfWeek: jiffy.startOfWeek,
+        relativeDateTime: jiffy.relativeDateTime);
   });
 
   group('Test parsing datetime from string', () {