Does NodaTime support relative time mapping?

I have a situation where relative time is more important for the user than absolute time. Thus, it is more important to be able to quickly say “the event happened 5 days and 5 hours ago” than “the event happened at 1 pm CDT and 5 pm CST in 5 days”.

We save our dates in UTC and convert to display for the user:

pDateTime = DateTime.SpecifyKind(pDateTime, DateTimeKind.Utc);
DateTimeZone dateTimeZone = DateTimeZoneProviders.Tzdb[pCurrentUser.PreferredTimezone];
return Instant.FromDateTimeUtc(pDateTime).InZone(dateTimeZone).ToString("HH':'mm':'ss' 'MM'/'dd'/'yy' 'x", CultureInfo.InvariantCulture);

We will use NodaTime 1.2 when it is fully released, and just used vanilla ToString before.

However, times using this pattern end with a daylight time state, rather than the current daylight state. This means that times look something like this: 16:15:32 10/25/13 CDTalthough we have now moved on to CST.

This is an absolute measure of time. This forces the user to do the logic: "How long has it been? Is it daylight saving time? If so, the difference is in x. If not, should I add or subtract the hour? It makes the difference y."

Meanwhile, a relative measure of time would display 15:15:32 10/25/13 CSTin the absence of DST. This forces the user to make no transformations and allows them to figure out what this time means in context much easier.

On a multi-date display, it can be difficult to make absolute time logic throughout the set. It is difficult to do this once. However, a friendly relative string like "5 hours ago" also forces them to decide both the date and time - this information is still important.

, / 24 , - , .

, NodaTime, , ?

+4
1

, , , . , : 16:15:32 10/25/13 CDT, CST.

, . / CST, , /, CDT, , IMO.

, " 5 5 ", " 1 CDT 5 CST 5 ".

/ , . ZonedDateTime Instant, Duration , , 5 5 . ( , - NodaConstants.TicksPerStandardDay .. DurationPattern, , .)

, , , :

  • OffsetDateTime; , , , , . , -5 CST -4 CDT.
  • UTC, .

, ZonedDateTime, (), - ().

+4

All Articles