- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用维基百科中的一些值,这些值在某些情况下是数百万年前的(例如月球的形成,维基数据报告其正在形成:“-4527000000-01-01T00:00:00Z”。在其他情况下,我只是查看可能是公元前 10000 年等的年份,仍然表示为“-10000-01-01T00:00:00Z”。
据我所知,测试 NodaTime 并阅读文档,这些古老的年份不受支持(或者我忽略了一些东西)。例如,这会失败:
OffsetDateTime defaultValue = new OffsetDateTime(new LocalDateTime(77, 1, 1, 0, 0), Offset.Zero);
var pattern = OffsetDateTimePattern.Create("yyyy-MM-ddTHH:mm:ss'Z'", CultureInfo.InvariantCulture, defaultValue);
string P = "-1000-01-25T20:34:25Z";
var result = pattern.Parse(P);
NodaTime.Text.UnparsableValueException: The value string includes a negative value where only a non-negative one is allowed. Value being parsed: '^-1000-01-25T20:34:25Z'. (^ indicates error position.)
at NodaTime.Text.ParseResult`1.GetValueOrThrow() in C:\Users\jon\Test\Projects\nodatime\build\releasebuild\src\NodaTime\Text\ParseResult.cs:line 81
at TryNodaTime.Program.Main(String[] args
使用 sing 这个字符串可以正常工作: string P = "1000-01-25T20:34:25Z";
我希望我只是忽略了一些明显的事情,即处理非常大的旧日期/年份。其他示例包括顺便说一句的旧城市,它们的确切日期远早于 0 年。
有关如何处理这些问题的指导将不胜感激。
编辑:找到这个示例,它要求我首先手动检测年份,然后使用 LocalDate(如果它为负数),但是,这并不能解决这里更大的问题,因为它在 -9999 以下失败:
LocalDate BCDATE = new LocalDate(Era.BeforeCommon, -15000, 10, 1);
Console.WriteLine($"BC: {BCDATE}");
最佳答案
Noda Time 不支持古代或遥远的 future 值。
支持的值范围是 in the user guide .
Noda Time can only represent values within a limited range. This is for pragmatic reasons: while it would be possible to try to model every instant since some estimate of the big bang until some expected "end of time," this would come at a significant cost to the experience of the 99.99% of programmers who just need to deal with dates and times in a reasonably modern (but not far-flung future) era.
The Noda Time 1.x releases supported years between around -27000 and +32000 (in the Gregorian calendar), but had significant issues around the extremes. Noda Time 2.0 has a smaller range, with more clearly-defined behaviour.
...
Additionally, all calendars are restricted to four digit formats, even in year-of-era representations, which avoids ever having to parse 5-digit years. This leads to a Gregorian calendar from 9999 BCE to 9999 CE inclusive, or -9998 to 9999 in "absolute" years. The range of other calendars is determined from this and from natural restrictions (such as not being proleptic).
恐怕我认为最好不要在这个用例中使用野田时间,而不是尝试解决它 - 除非你可以有效地逐字报告遥远的日期并做没有与他们一起进行其他工作。
对此感到抱歉 - 这是尝试支持所有用例的情况之一,这确实会损害更常见的用例:(
关于c# - 野田时代与远古时代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54374556/
我是一名优秀的程序员,十分优秀!