FatulM / shamsi_date

A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian, Jalaali, شمسی or خورشیدی) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi or میلادی) date and times.
https://pub.dev/packages/shamsi_date
BSD 3-Clause "New" or "Revised" License
78 stars 10 forks source link

month range error #20

Closed HamedDN closed 1 year ago

HamedDN commented 1 year ago

there is a problem on (dateProvider as Jalali).withDay(30).addMonths(-1) when month is 1 and day is 30 or 31.

FatulM commented 1 year ago

Hi, there is not a problem :smiley: with this operation you will get Jalali(year, 12, 30) and since the last year is not a leap year, this is not a valid date and so it will throw an error

FatulM commented 1 year ago

what do you want to achieve exactly ?

HamedDN commented 1 year ago

what do you want to achieve exactly ?

i want if the before month does not have the 30th day it give me the last day of the before month, Not "RageError"

FatulM commented 1 year ago

this is not done automatically in shamsi_date library, but you can do something like this:

tmp = date.addMonth(-1);
newDate = tmp.withDay(tmp.monthLength)

is this working for you ? @HamedDN

or i think something like this will also work:

date.withDay(1) - 1

or equivalently

date.withDay(1).addDays(-1)
HamedDN commented 1 year ago

this is not done automatically in shamsi_date library, but you can do something like this:

tmp = date.addMonth(-1);
newDate = tmp.withDay(tmp.monthLength)

is this working for you ? @HamedDN

yeah it work, i did this in my project, but it can be somthing that you add to your package.