minor fix
This commit is contained in:
parent
05aa7641f7
commit
77bf6a2b58
2 changed files with 13 additions and 1 deletions
|
@ -24,6 +24,9 @@ import 'package:flutter/foundation.dart';
|
||||||
class VideoMetadataFormatter {
|
class VideoMetadataFormatter {
|
||||||
static final _dateY4M2D2H2m2s2Pattern = RegExp(r'(\d{4})[-/](\d{2})[-/](\d{2}) (\d{2}):(\d{2}):(\d{2})');
|
static final _dateY4M2D2H2m2s2Pattern = RegExp(r'(\d{4})[-/](\d{2})[-/](\d{2}) (\d{2}):(\d{2}):(\d{2})');
|
||||||
static final _dateY4M2D2H2m2s2APmPattern = RegExp(r'(\d{4})[-/](\d{2})[-/](\d{2})T(\d+):(\d+):(\d+) ([ap]m)Z');
|
static final _dateY4M2D2H2m2s2APmPattern = RegExp(r'(\d{4})[-/](\d{2})[-/](\d{2})T(\d+):(\d+):(\d+) ([ap]m)Z');
|
||||||
|
static final _ambiguousDatePatterns = {
|
||||||
|
RegExp(r'^\d{2}[-/]\d{2}[-/]\d{4}$'),
|
||||||
|
};
|
||||||
static final _durationPattern = RegExp(r'(\d+):(\d+):(\d+)(.\d+)');
|
static final _durationPattern = RegExp(r'(\d+):(\d+):(\d+)(.\d+)');
|
||||||
static final _locationPattern = RegExp(r'([+-][.0-9]+)');
|
static final _locationPattern = RegExp(r'([+-][.0-9]+)');
|
||||||
static final Map<String, String> _codecNames = {
|
static final Map<String, String> _codecNames = {
|
||||||
|
@ -93,7 +96,7 @@ class VideoMetadataFormatter {
|
||||||
int? dateMillis;
|
int? dateMillis;
|
||||||
if (isDefined(dateString)) {
|
if (isDefined(dateString)) {
|
||||||
dateMillis = parseVideoDate(dateString);
|
dateMillis = parseVideoDate(dateString);
|
||||||
if (dateMillis == null) {
|
if (dateMillis == null && !isAmbiguousDate(dateString)) {
|
||||||
await reportService.recordError('getCatalogMetadata failed to parse date=$dateString for mimeType=${entry.mimeType} entry=$entry', null);
|
await reportService.recordError('getCatalogMetadata failed to parse date=$dateString for mimeType=${entry.mimeType} entry=$entry', null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,6 +110,10 @@ class VideoMetadataFormatter {
|
||||||
return entry.catalogMetadata;
|
return entry.catalogMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isAmbiguousDate(String dateString) {
|
||||||
|
return _ambiguousDatePatterns.any((pattern) => pattern.hasMatch(dateString));
|
||||||
|
}
|
||||||
|
|
||||||
static int? parseVideoDate(String dateString) {
|
static int? parseVideoDate(String dateString) {
|
||||||
final date = DateTime.tryParse(dateString);
|
final date = DateTime.tryParse(dateString);
|
||||||
if (date != null) {
|
if (date != null) {
|
||||||
|
|
|
@ -10,4 +10,9 @@ void main() {
|
||||||
expect(VideoMetadataFormatter.parseVideoDate('2021/10/31 21:23:17'), DateTime(2021, 10, 31, 21, 23, 17).millisecondsSinceEpoch);
|
expect(VideoMetadataFormatter.parseVideoDate('2021/10/31 21:23:17'), DateTime(2021, 10, 31, 21, 23, 17).millisecondsSinceEpoch);
|
||||||
expect(VideoMetadataFormatter.parseVideoDate('2021-09-10T7:14:49 pmZ'), DateTime(2021, 9, 10, 19, 14, 49).millisecondsSinceEpoch);
|
expect(VideoMetadataFormatter.parseVideoDate('2021-09-10T7:14:49 pmZ'), DateTime(2021, 9, 10, 19, 14, 49).millisecondsSinceEpoch);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Ambiguous date', () {
|
||||||
|
expect(VideoMetadataFormatter.isAmbiguousDate('2011-05-08T03:46+09:00'), false);
|
||||||
|
expect(VideoMetadataFormatter.isAmbiguousDate('05-08-2011'), true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue