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.
25 lines
590 B
25 lines
590 B
6 years ago
|
import 'package:intl/intl.dart';
|
||
|
|
||
|
class WeekLabel {
|
||
|
int weekNum;
|
||
|
String label;
|
||
|
|
||
|
WeekLabel(this.weekNum, this.label);
|
||
|
|
||
|
WeekLabel.forDate(DateTime date, String label) {
|
||
|
this.label = label;
|
||
|
int year = getYear(date);
|
||
|
int weekOfYearNum = getWeekNumber(date);
|
||
|
this.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();
|
||
|
}
|
||
|
}
|