Note: Load the modified tag properly

This commit is contained in:
Vishesh Handa
2019-12-14 12:05:52 +01:00
parent 106953ad68
commit bc6f7c1b8f
2 changed files with 25 additions and 16 deletions

@ -94,22 +94,10 @@ class Note with ChangeNotifier implements Comparable<Note> {
_data = data;
if (data.props.containsKey("created")) {
var createdStr = data.props['created'].toString();
try {
_created = DateTime.parse(data.props['created']).toLocal();
} catch (ex) {
// Ignore it
}
if (_created == null) {
var regex = RegExp(
r"(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})\+(\d{2})\:(\d{2})");
if (regex.hasMatch(createdStr)) {
// FIXME: Handle the timezone!
createdStr = createdStr.substring(0, 19);
_created = DateTime.parse(createdStr);
}
}
_created = parseDateTime(data.props['created'].toString());
}
if (data.props.containsKey("modified")) {
_modified = parseDateTime(data.props['modified'].toString());
}
_created ??= DateTime(0, 0, 0, 0, 0, 0, 0, 0);

@ -35,3 +35,24 @@ String toIso8601WithTimezone(DateTime dt, [Duration offset]) {
return result + sign + hourStr + ':' + minutesStr;
}
DateTime parseDateTime(String str) {
DateTime dt;
try {
dt = DateTime.parse(str).toLocal();
} catch (ex) {
// Ignore it
}
if (dt == null) {
var regex = RegExp(
r"(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})\+(\d{2})\:(\d{2})");
if (regex.hasMatch(str)) {
// FIXME: Handle the timezone!
str = str.substring(0, 19);
dt = DateTime.parse(str);
}
}
return dt;
}