jama5262 / jiffy

Jiffy is a Flutter (Android, IOS and Web) date time package for parsing, manipulating, querying and formatting dates
https://pub.dev/packages/jiffy
MIT License
576 stars 124 forks source link

endOf doesn't work as intendet in Chrome #252

Open yahooooza opened 11 months ago

yahooooza commented 11 months ago

Describe the bug

The method endOf is decribed as giving the last microsecond that belong to the unit given. In Chrome somehow this doesn't work. And therefore the function isSame doesnt work as expected either.

How to reproduce the bug

Her an Example to show the Bug:

Unit unit = Unit.month;
  Jiffy first = Jiffy.parseFromDateTime(DateTime(2023,1,25));
  Jiffy second = Jiffy.parseFromDateTime(DateTime(2023,2,1));
  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: ListView(
          children: <Widget>[
            ListTile(
              title: Text("Comparing following two dates"),
              subtitle: Text(first.dateTime.toIso8601String() + " and " + second.dateTime.toIso8601String()),
            ),
            Row(
              children: [
                Padding(
                  padding: EdgeInsets.only(left:16),
                  child: SizedBox(
                    width: 200,
                    child: DropdownButton<Unit>(
                      value: unit,
                      icon: const Icon(Icons.monetization_on),
                      onChanged: (Unit? value) {
                        setState(() {
                          unit = value!;
                        });
                      },
                      items: Unit.values.map<DropdownMenuItem<Unit>>((Unit value) {
                        return DropdownMenuItem<Unit>(
                          value: value,
                          child: Text(value.toString()),
                        );
                      }).toList(),
                    ),
                  ),
                ),
                Expanded(child: SizedBox.shrink()),
              ],
            ),
            ListTile(
              title: Text("startOf works as intendent"),
              subtitle: Text(first.startOf(unit).dateTime.toIso8601String() + " and " + second.startOf(unit).dateTime.toIso8601String()),
            ),
            ListTile(
              title: Text("but endOf doesnt work as intended in chrome"),
              subtitle: Text(first.endOf(unit).dateTime.toIso8601String() + " and " + second.endOf(unit).dateTime.toIso8601String()),
            ),
            ListTile(
              title: Text("And Therefore isSame doesnt work as intended, here an Example for Unit Month"),
              subtitle: Text("First and Second are the same in month unit: ${first.isSame(second,unit: Unit.month)}"),
            )
         ],
      ),
    );
  }

What is the expected behavior

For the date 2023-01-25, endOf for the unit Unit.month should return 2023-01-25T23:59.59.999999. Also if comparing the Jiffy Dates 2023-01-25 and 2023-02-01 isSame should return false.

Screenshots

Jify Bug

Additional information

Tested on : Chrome 117.0.5938.92 Flutter 3.13.4 On Linux In Debug Mode and as Release Version deployed on a server

jigneshpandav commented 11 months ago

Yes, facing the same issue. Getting 2023-11-01 00:00:00.000 instead of 2023-10-31 11:59:59.999.

DateTime.now().endOf(Unit.month).dateTime;

Tested on : Chrome Version 117.0.5938.149 (Official Build) (arm64)

Flutter 3.13.7 • channel stable • https://github.com/flutter/flutter.git Framework • revision 2f708eb839 (7 days ago) • 2023-10-09 09:58:08 -0500 Engine • revision a794cf2681 Tools • Dart 3.1.3 • DevTools 2.25.0

On MacMini