-
Notifications
You must be signed in to change notification settings - Fork 306
Fix datetime serialization to always output 6 decimal places for microseconds #1687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,4 +142,31 @@ public void ReadWriteDatesJson() | |
|
|
||
| Assert.Equal(kManifest, jsonFromObj2); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DateTimeWithFractionalSecondsAlwaysHasSixDigits() | ||
| { | ||
| // Test that datetime fields with fractional seconds always output exactly 6 decimal places | ||
| // This is required by Kubernetes API which expects RFC3339Micro format | ||
|
|
||
| // Create a datetime with 5 digits of precision (962170 microseconds = .96217 seconds) | ||
| var dt = new DateTime(2025, 11, 17, 22, 52, 34, 962, DateTimeKind.Utc).AddTicks(1700); | ||
|
|
||
| var secret = new V1Secret | ||
| { | ||
| Metadata = new V1ObjectMeta | ||
| { | ||
| Name = "test-secret", | ||
| CreationTimestamp = dt, | ||
| }, | ||
| }; | ||
|
|
||
| var json = KubernetesJson.Serialize(secret); | ||
|
|
||
| // Verify the datetime is serialized with exactly 6 decimal places | ||
| Assert.Contains("2025-11-17T22:52:34.962170Z", json); | ||
|
|
||
| // Also verify it doesn't have 5 digits (which would fail in Kubernetes) | ||
| Assert.DoesNotContain("2025-11-17T22:52:34.96217Z", json); | ||
| } | ||
|
Comment on lines
+146
to
+171
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] For consistency with the existing format strings (like
RFC3339FormatandRFC3339MicroFormat), consider using quoted separators:"yyyy'-'MM'-'dd'T'HH':'mm':'ss"instead of"yyyy-MM-dd'T'HH:mm:ss".