extractTs static method
Extracts the _ts
field (timestamp) from a JSON string.
Returns -1 if _ts
is not found or parsing fails.
Implementation
static int extractTs(String json) {
try {
final Map<String, dynamic> map = jsonDecode(json);
if (map.containsKey('_ts')) {
final tsValue = map['_ts'];
if (tsValue is int) {
return tsValue;
}
if (tsValue is String) {
return int.tryParse(tsValue) ?? -1;
}
}
} catch (_) {
// ignore parsing errors, treat as oldest
}
return -1;
}