Last active
July 27, 2021 12:54
-
-
Save ArefMozafari/3412975ffb33f726747a4dbc481e1bf9 to your computer and use it in GitHub Desktop.
Flutter/Dart - Range of Dates for today, current week, current month and current year in Shamsi/Persian/Jalali Calendar using shamsi_date package.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//First you need install shamsi_date package from pub.dev and then import it. | |
import 'package:shamsi_date/shamsi_date.dart'; | |
void main (){ | |
final JalaliRange todayRange = | |
JalaliRange(start: Jalali.now(), end: Jalali.now()); | |
//Shamsi_date package doesn't support .add and .subtract (since this version) | |
//So we use DateTime and convert it to Jalali | |
final JalaliRange thisWeekRange = JalaliRange( | |
start: Jalali.fromDateTime( | |
DateTime.now().subtract(Duration(days: DateTime.now().weekday + 1))), | |
end: Jalali.fromDateTime(DateTime.now().add( | |
Duration(days: DateTime.daysPerWeek - DateTime.now().weekday - 2)))); | |
final JalaliRange thisMonthRange = JalaliRange( | |
start: Jalali(Jalali.now().year, Jalali.now().month, 1), | |
end: Jalali( | |
Jalali.now().year, Jalali.now().month, Jalali.now().monthLength)); | |
final JalaliRange thisYearRange = JalaliRange( | |
start: Jalali(Jalali.now().year, 1, 1), | |
end: Jalali( | |
Jalali.now().year, 12, Jalali(Jalali.now().year, 12).monthLength)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment