-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
github-actions[bot]
committed
Aug 30, 2024
1 parent
dec8bc1
commit 590c20f
Showing
4 changed files
with
217 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/libs/DeepInfra/Generated/JsonConverters.UnixTimestamp.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#nullable enable | ||
|
||
namespace OpenApiGenerator.JsonConverters | ||
{ | ||
/// <inheritdoc /> | ||
public class UnixTimestampJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::System.DateTimeOffset> | ||
{ | ||
/// <inheritdoc /> | ||
public override global::System.DateTimeOffset Read( | ||
ref global::System.Text.Json.Utf8JsonReader reader, | ||
global::System.Type typeToConvert, | ||
global::System.Text.Json.JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType == global::System.Text.Json.JsonTokenType.Number) | ||
{ | ||
if (reader.TryGetInt64(out long unixTimestamp)) | ||
{ | ||
return global::System.DateTimeOffset.FromUnixTimeSeconds(unixTimestamp); | ||
} | ||
if (reader.TryGetInt32(out int unixTimestampInt)) | ||
{ | ||
return global::System.DateTimeOffset.FromUnixTimeSeconds(unixTimestampInt); | ||
} | ||
} | ||
|
||
return default; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void Write( | ||
global::System.Text.Json.Utf8JsonWriter writer, | ||
global::System.DateTimeOffset value, | ||
global::System.Text.Json.JsonSerializerOptions options) | ||
{ | ||
long unixTimestamp = value.ToUnixTimeSeconds(); | ||
writer.WriteNumberValue(unixTimestamp); | ||
} | ||
} | ||
} |
Oops, something went wrong.