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
588 stars 126 forks source link

Error in fromNow() method using String as input #255

Open MaxSchilling opened 11 months ago

MaxSchilling commented 11 months ago

Describe the bug

After the update from Jiffy 5 to version 6.2.1, the fromNow() method is failing using a Jiffy.parse(createdAt).fromNow() - recommending using a pattern (Error message: "Could not read date time of input 2023-11-15T08:48:02.169584+00:00, try using a pattern, e.g. input: "12, Oct", pattern: "dd, MMM""

If I then add a pattern, like also suggested here: https://github.com/jama5262/jiffy/issues/227 Trying this: Jiffy.parse(createdAt, pattern: 'yyyy-MM-ddThh:mm:ss', isUtc: true) .fromNow();

Results in: "Could not parse input 202311-15T08:48:02.169584+00:00, failed with the following error: FormatException: Trying to read - from 202311-15T08:48:02.169584+00:00 at 10"

the createdAt timestamp as input was: 2023-11-15T08:48:02.169584+00:00 Somehow during the internal _parse methods, the first "-" gets lost when using a pattern.

How to reproduce the bug

  1. Try to use the fromNow() method with any Iso date string and the respective pattern
  2. Find error

What is the expected behavior

Correct calculation of "fromNow" which also includes the timezone / UTC true/false

Screenshots Step before with correct String in parser.dart: image

Step afterwards with missing "-": image

Step If applicable, add screenshots to help explain your problem.

Additional information

Converting the String-date in a DateTime object and calculating the fromNow() from there works fine.

debjeetproso commented 6 months ago

Have you found any solution for this ?

jama5262 commented 6 months ago

@MaxSchilling I was not able to reproduce the issue, in v6.2.1, can you try again, but using Jiffy v6.3.0?