mirror of https://github.com/flutter/samples.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
560 B
24 lines
560 B
import 'package:intl/intl.dart';
|
|
|
|
class WeekLabel {
|
|
int? weekNum;
|
|
String label;
|
|
|
|
WeekLabel(this.weekNum, this.label);
|
|
|
|
WeekLabel.forDate(DateTime date, this.label) {
|
|
int year = getYear(date);
|
|
int weekOfYearNum = getWeekNumber(date);
|
|
weekNum = 9 + ((year - 2015) * 52) + weekOfYearNum;
|
|
}
|
|
|
|
int getYear(DateTime date) {
|
|
return int.parse(DateFormat('y').format(date));
|
|
}
|
|
|
|
int getWeekNumber(DateTime date) {
|
|
int dayOfYear = int.parse(DateFormat('D').format(date));
|
|
return ((dayOfYear - date.weekday + 10) / 7).floor();
|
|
}
|
|
}
|