Time format used for started time in services is culture dependent.
niklasfp opened this issue · 2 comments
Observed behavior
"Micro" services started time is depending on the .net current culture, which can lead to a wrong format on some cultures, like "en-DK", so the format is depending on the machine running the service. And this causes the nats-cli to crash with parsing error when getting info from a service started on a machine with one of those cultures.
From a machine running en-DK
culture:
❯ nats micro info "Test-DotNet"
nats: error: parsing time "2024-02-04T16.22.01.0841150Z" as "2006-01-02T15:04:05Z07:00": cannot parse ".22.01.0841150Z" as ":"
There are two ways to fix this:
-
Pass
CultureInfo.InvariantCulture
when doingDateTimeOffset.UtcNow.ToString(...
-
Use change the format
yyyy'-'MM'-'ddTHH':'mm':'ss'.'fffffff'Z'
this will not consider culture specific time separators
The output below shows the different effects the "Explicit format" vs the format currently in use "Loose format"
Explicit format
------------
Culture: () Invariant Language (Invariant Country)
Date (iso): 2024-02-04T15:06:57.8534311+00:00
Format : yyyy'-'MM'-'ddTHH':'mm':'ss'.'fffffff'Z'
Result: 2024-02-04T15:06:57.8534311Z
Culture: (da-DK) Danish (Denmark)
Date (iso): 2024-02-04T15:06:57.8534311+00:00
Format : yyyy'-'MM'-'ddTHH':'mm':'ss'.'fffffff'Z'
Result: 2024-02-04T15:06:57.8534311Z
Culture: (en-DK) English (Denmark)
Date (iso): 2024-02-04T15:06:57.8534311+00:00
Format : yyyy'-'MM'-'ddTHH':'mm':'ss'.'fffffff'Z'
Result: 2024-02-04T15:06:57.8534311Z
Loose format
------------
Culture: () Invariant Language (Invariant Country)
Date (iso): 2024-02-04T15:06:57.8534311+00:00
Format : yyyy-MM-ddTHH:mm:ss.fffffffZ
Result: 2024-02-04T15:06:57.8534311Z
Culture: (da-DK) Danish (Denmark)
Date (iso): 2024-02-04T15:06:57.8534311+00:00
Format : yyyy-MM-ddTHH:mm:ss.fffffffZ
Result: 2024-02-04T15:06:57.8534311Z
Culture: (en-DK) English (Denmark)
Date (iso): 2024-02-04T15:06:57.8534311+00:00
Format : yyyy-MM-ddTHH:mm:ss.fffffffZ
Result: 2024-02-04T15.06.57.8534311Z
Expected behavior
Services started with nats.net exposes a datetime format for the started time that can be parsed by nats cli
Server and client version
❯ nats-server --version
nats-server: v2.10.9
❯ nats --version
0.1.1
Host environment
Mac OS Sonoma 14.3 - M2 (arm64)
Platform does not matter, it's a .net culture thing, same date problem is observed on windows 11 (arm64)
Steps to reproduce
Start a service using the lates pre-release of Nats.Net.v2 and use the nats cli to get info for that service, in my case I called it "Test-DotNet" when reproducing this error.
❯ nats micro info "Test-DotNet"
nats: error: parsing time "2024-02-04T16.22.01.0841150Z" as "2006-01-02T15:04:05Z07:00": cannot parse ".22.01.0841150Z" as ":"