mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-20 04:42:59 +08:00
Note: Load the modified tag properly
This commit is contained in:
lib
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user