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.
samples/web/github_dataviz/lib/data/week_label.dart

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();
}
}