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

Fix patch:
diff --git a/doc/README.md b/doc/README.md
index 7570728..c9a0555 100644
--- a/doc/README.md
+++ b/doc/README.md
@@ -712,7 +712,7 @@ jiffy1.from(jiffy2); // like a day ago, i think
 
 ## Getting the locale information
 ```dart
-final locale = Jiffy.now().locale; // Returns a locale object
+final locale = Jiffy.now().locale; // Returns a jiffy locale object
 final localeCode = locale.code;
 final localeStartOfWeek = locale.startOfWeek;
 final localeCode = locale.ordinals;
diff --git a/lib/jiffy.dart b/lib/jiffy.dart
index bc33606..c412795 100644
--- a/lib/jiffy.dart
+++ b/lib/jiffy.dart
@@ -5,7 +5,7 @@ library;
 
 export 'src/enums/unit.dart';
 export 'src/enums/start_of_week.dart';
-export 'src/locale/locale.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 be07e1b..26b50b0 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/locale.dart';
+import 'locale/jiffy_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, Locale locale) {
+  String format(DateTime dateTime, String pattern, JiffyLocale 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,
-      Locale locale, bool withPrefixAndSuffix) {
+      JiffyLocale locale, bool withPrefixAndSuffix) {
     final isFirstDateTimeSameOrAfterSecondDateTime = _query.isSameOrAfter(
         firstDateTime, secondDateTime, Unit.microsecond, locale.startOfWeek);
 
@@ -88,7 +88,7 @@ class Display {
   }
 
   String toAsRelativeDateTime(DateTime firstDateTime, DateTime secondDateTime,
-      Locale locale, bool withPrefixAndSuffix) {
+      JiffyLocale locale, bool withPrefixAndSuffix) {
     return fromAsRelativeDateTime(
         secondDateTime, firstDateTime, locale, withPrefixAndSuffix);
   }
diff --git a/lib/src/getter.dart b/lib/src/getter.dart
index 25a9203..569b8b3 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/locale.dart';
+import 'locale/jiffy_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, Locale locale) {
+  int weekOfYear(DateTime dateTime, JiffyLocale 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, Locale locale) {
+  int quarterOfYear(DateTime dateTime, JiffyLocale locale) {
     return _toInt(DateFormat('Q', locale.code).format(dateTime), locale);
   }
 
-  int dayOfYear(DateTime dateTime, Locale locale) {
+  int dayOfYear(DateTime dateTime, JiffyLocale locale) {
     return _toInt(DateFormat('D', locale.code).format(dateTime), locale);
   }
 
@@ -74,7 +74,7 @@ class Getter {
     return result;
   }
 
-  int _toInt(String localeNumber, Locale locale) {
+  int _toInt(String localeNumber, JiffyLocale locale) {
     return NumberFormat.decimalPattern(locale.code).parse(localeNumber).toInt();
   }
 
diff --git a/lib/src/jiffy.dart b/lib/src/jiffy.dart
index 7b0de1a..e9e1526 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/locale.dart';
+import './locale/jiffy_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 Locale _locale;
+  late JiffyLocale _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 = Locale(
+    _locale = JiffyLocale(
         code: currentLocale,
         startOfWeek: getStartOfWeek(currentLocale),
         ordinals: getOrdinals(currentLocale),
@@ -318,8 +318,8 @@ class Jiffy {
     }
   }
 
-  /// Returns the [Locale].
-  Locale get locale => _locale;
+  /// Returns the [JiffyLocale].
+  JiffyLocale get locale => _locale;
 
   /// Creates and returns a new [Jiffy] instance with the same date and time
   /// as the original instance.
@@ -387,7 +387,7 @@ class Jiffy {
   /// leap year.
   int get dayOfYear => _getter.dayOfYear(dateTime, _locale);
 
-  /// Returns the week number of the year based on the current [Locale]'s
+  /// Returns the week number of the year based on the current [JiffyLocale]'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/locale.dart b/lib/src/locale/jiffy_locale.dart
similarity index 96%
rename from lib/src/locale/locale.dart
rename to lib/src/locale/jiffy_locale.dart
index 29d3706..71fa1ad 100644
--- a/lib/src/locale/locale.dart
+++ b/lib/src/locale/jiffy_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 Locale {
+class JiffyLocale {
   /// Returns the locale code for this locale.
   ///
   /// The locale code is a string identifier that uniquely identifies a
@@ -27,7 +27,7 @@ class Locale {
   /// a specific locale.
   final RelativeDateTime relativeDateTime;
 
-  Locale({
+  JiffyLocale({
     required this.code,
     required this.ordinals,
     required this.startOfWeek,
diff --git a/lib/src/parser.dart b/lib/src/parser.dart
index 4e107b6..4c5a750 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/locale.dart';
+import 'locale/jiffy_locale.dart';
 import 'utils/jiffy_exception.dart';
 
 class Parser {
@@ -12,7 +12,7 @@ class Parser {
   Parser(this._getter);
 
   DateTime fromString(
-      String input, String? pattern, Locale locale, bool isUtc) {
+      String input, String? pattern, JiffyLocale 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 5953e82..179c485 100644
--- a/test/src/display_test.dart
+++ b/test/src/display_test.dart
@@ -13,7 +13,7 @@ void main() {
 
   final underTest = Display(getter, manipulator, query);
 
-  late Locale locale;
+  late JiffyLocale locale;
 
   setUp(() async {
     Jiffy.setLocale("en");
diff --git a/test/src/getter_test.dart b/test/src/getter_test.dart
index ac92cb5..c8b6969 100644
--- a/test/src/getter_test.dart
+++ b/test/src/getter_test.dart
@@ -4,7 +4,7 @@ import 'package:test/test.dart';
 
 final underTest = Getter();
 
-late Locale locale;
+late JiffyLocale locale;
 
 void main() {
   setUp(() async {
diff --git a/test/src/locale/relative_date_time_test.dart b/test/src/locale/relative_date_time_test.dart
index 8a44bd9..ade2132 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/locale.dart';
+import 'package:jiffy/src/locale/jiffy_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 = Locale(
+        final locale = JiffyLocale(
             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 1466415..e9b85c6 100644
--- a/test/src/parser_test.dart
+++ b/test/src/parser_test.dart
@@ -8,7 +8,7 @@ void main() {
   final getter = Getter();
   final underTest = Parser(getter);
 
-  late Locale locale;
+  late JiffyLocale locale;
 
   setUp(() async {
     Jiffy.setLocale("en");