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

25 lines
590 B

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