public string FormatTime(TimePoint point, TimeFormat format) { DaysToDaysMonthsYears((long)Floor(point.Tick / m_ticksPerDay) + m_startDay, out var years, out var months, out var days); var date = new DateTime(years, months, days); return((format == TimeFormat.Long ? "{0:D}" : "{0:d}").FormatCurrentCulture(date)); }
public string FormatOffsetFrom(TimePoint point, TimeOffset offset, TimeFormat format) { if (offset.TickOffset < 0) { throw new ArgumentException($"{nameof(offset)} must be positive"); } var startTotalDays = (long)Floor(point.Tick / m_ticksPerDay) + m_startDay; DaysToDaysMonthsYears(startTotalDays, out var startYears, out var startMonths, out var startDays); var endTotalDays = startTotalDays + offset.TickOffset; DaysToDaysMonthsYears(endTotalDays, out var endYears, out var endMonths, out var endDays); var days = endDays >= startDays ? endDays - startDays : GetDaysInMonth(startMonths, startYears) - startDays + endDays; var months = endMonths >= startMonths ? endMonths - startMonths : 12 - startMonths + endMonths; if (endDays < startDays) { months--; } var years = endYears - startYears; if (endMonths < startMonths) { years--; } var output = years != 0 ? OurResources.ResourceManager.Pluralize(format == TimeFormat.Long ? "TimeOffsetYearLong" : "TimeOffsetYearShort", years).FormatCurrentCulture(years) : ""; var monthsOutput = months != 0 ? OurResources.ResourceManager.Pluralize(format == TimeFormat.Long ? "TimeOffsetMonthLong" : "TimeOffsetMonthShort", months).FormatCurrentCulture(months) : null; if (monthsOutput != null) { if (output.Length != 0) { output = OurResources.TimeOffsetTermJoin.FormatCurrentCulture(output, monthsOutput); } else { output = monthsOutput; } } var daysOutput = days != 0 ? OurResources.ResourceManager.Pluralize(format == TimeFormat.Long ? "TimeOffsetDayLong" : "TimeOffsetDayShort", days).FormatCurrentCulture(days) : null; if (daysOutput != null) { if (output.Length != 0) { output = OurResources.TimeOffsetTermJoin.FormatCurrentCulture(output, daysOutput); } else { output = daysOutput; } } return(output); }