Skip to content

Commit 0b42b76

Browse files
committed
fix: add Flickr date string fallback to TimestampToDateTimeConverter
- Try parsing "yyyy-MM-dd HH:mm:ss" format when Unix timestamp fails - Re-enable DateTaken assertion in PhotoDescriptionIsDeserialized test
1 parent a186af9 commit 0b42b76

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/Flickr.Net.Test/Entities/PhotoTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public void PhotoDescriptionIsDeserialized()
3636
Assert.False(result.HasError);
3737
var photo = result.Content.Values[0];
3838
Assert.Equal("A test description", photo.Description.Content);
39-
// Note: DateTaken currently returns default due to TimestampToDateTimeConverter
40-
// not supporting Flickr's "YYYY-MM-DD HH:mm:ss" date format.
41-
// Assert.Equal(new DateTime(2024, 3, 15, 14, 30, 0), photo.DateTaken);
39+
Assert.Equal(new DateTime(2024, 3, 15, 14, 30, 0), photo.DateTaken);
4240
}
4341

4442
[Fact]

src/Flickr.Net/Internals/JsonConverters/TimestampToDateTimeConverter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
3232
}
3333
catch (FormatException)
3434
{
35+
if (DateTime.TryParseExact(value, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsed))
36+
{
37+
return parsed;
38+
}
39+
3540
return DateTime.MinValue;
3641
}
3742
}

0 commit comments

Comments
 (0)