Week.fromISOString constructor
Week.fromISOString(
- String isoString
Return a week initialized from an ISO formatted string like "2020W01" or "2020-W01" (or even "2020-W1" or "2020W1").
Implementation
factory Week.fromISOString(String isoString) {
final parts = isoString.split('W');
var yearStr = parts.first;
if (yearStr.length > 4) {
// If separated with - (e.g. "2020-W01")
yearStr = yearStr.substring(0, 4);
}
final weekNumberStr = parts[1];
final year = int.parse(yearStr);
final weekNumber = int.parse(weekNumberStr);
return Week(year: year, weekNumber: weekNumber);
}