dotnet / dotnet/dotnet-api-docs

Remarks for DateTime.MinValue and DateTime.MaxValue say the values are equivalent to UTC but they use DateTimeKind.Unspecified

Aperta
#9,845 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area-System.DateTime Pri3 untriaged
Lingua principale
C#
Stelle
949
Fork
1.7k
Merge medio
2g 19h
PR unite (30g)
52

Descrizione

[DateTime.MinValue](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.minvalue?view=net-8.0) says:

> The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 0001, in the Gregorian calendar.

[DateTime.MaxValue](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.maxvalue?view=net-8.0) says:

> The value of this constant is equivalent to 23:59:59.9999999 UTC, December 31, 9999 in the Gregorian calendar, exactly one 100-nanosecond tick before 00:00:00 UTC, January 1, 10000.

I interpreted this to mean that both `MinValue` and `MaxValue` use `DateTimeKind.Utc`, but that's not the case:
- [.NET Framework 4.8](https://referencesource.microsoft.com/#mscorlib/system/datetime.cs,116):
```
public static readonly DateTime MinValue = new DateTime(MinTicks, DateTimeKind.Unspecified);
public static readonly DateTime MaxValue = new DateTime(MaxTicks, DateTimeKind.Unspecified);
```
- [.NET 8.0.4](https://github.com/dotnet/runtime/blob/v8.0.4/src/libraries/System.Private.CoreLib/src/System/DateTime.cs#L133): (`DateTimeKind.Unspecified` has value 0)
```
public static readonly DateTime MinValue;
public static readonly DateTime MaxValue = new DateTime(MaxTicks, DateTimeKind.Unspecified);
```

Whether `DateTimeKind.Unspecified` is equivalent to `DateTimeKind.Utc` seems to depend on what operation you perform: `ToString("R")` prints "GMT", but [converting between time zones](https://learn.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones) may treat `DateTimeKind.Unspecified` as either local time or UTC, depending on the conversion. For example, `Console.WriteLine(System.DateTime.MinValue.ToUniversalTime().ToString("R"));` prints `Mon, 01 Jan 0001 06:00:00 GMT` on a machine with a local time zone of CDT.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia confrontando le annotazioni dell'API relative a DateTime.MinValue e DateTime.MaxValue con il codice sorgente collegato di DateTime di .NET Framework e .NET 8, quindi esamina il comportamento documentato della conversione del fuso orario. Il lavoro è completato quando entrambe le annotazioni descrivono accuratamente i rispettivi valori DateTimeKind.Unspecified ed evitano di implicare che siano UTC.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.