parseTTL static method
Parse TTL string to DateTime Supports formats: "2026-01-12T23:59:59" or "2026-01-12"
Implementation
static DateTime? parseTTL(String? ttlString) {
if (ttlString == null || ttlString.isEmpty) {
return null;
}
try {
// Try full datetime format: 2026-01-12T23:59:59
final fullFormat = DateFormat("yyyy-MM-dd'T'HH:mm:ss");
return fullFormat.parse(ttlString);
} catch (e) {
try {
// Fallback to date-only format: 2026-01-12
final dateOnly = ttlString.split('T')[0];
final dateFormat = DateFormat("yyyy-MM-dd");
return dateFormat.parse(dateOnly);
} catch (e) {
// If both formats fail, return null
return null;
}
}
}