Ejemplo n.º 1
0
        public TimeFormatter(CultureInfo culture,
                             string dateTimeFormat = null,
                             string shortDateFormat = null,
                             string longTimeFormat = null,
                             string shortTimeFormat = null,
                             string contextSeparator = DefaultContextSeparator,
                             string startEndSeparator = DefaultStartEndSeparator,
                             string durationSeparator = DefaultDurationSeparator,
                             DurationFormatKind durationFormatKind = DurationFormatKind.Compact,
                             bool useDurationSeconds = false,
                             bool useIsoIntervalNotation = false) {
            Culture = culture.GetOrCurrentCulture();

            DateTimeFormat = dateTimeFormat;
            ShortDateFormat = shortDateFormat;
            LongTimeFormat = longTimeFormat;
            ShortTimeFormat = shortTimeFormat;

            ContextSeparator = contextSeparator ?? DefaultContextSeparator;
            StartEndSeparator = startEndSeparator ?? DefaultStartEndSeparator;
            DurationSeparator = durationSeparator ?? DefaultDurationSeparator;

            DurationKind = durationFormatKind;
            UseDurationSeconds = useDurationSeconds;
            UseIsoIntervalNotation = useIsoIntervalNotation;
        }
Ejemplo n.º 2
0
        public TimeFormatter(CultureInfo culture,
                             string dateTimeFormat    = null,
                             string shortDateFormat   = null,
                             string longTimeFormat    = null,
                             string shortTimeFormat   = null,
                             string contextSeparator  = DefaultContextSeparator,
                             string startEndSeparator = DefaultStartEndSeparator,
                             string durationSeparator = DefaultDurationSeparator,
                             DurationFormatKind durationFormatKind = DurationFormatKind.Compact,
                             bool useDurationSeconds     = false,
                             bool useIsoIntervalNotation = false)
        {
            Culture = culture.GetOrCurrentCulture();

            DateTimeFormat  = dateTimeFormat;
            ShortDateFormat = shortDateFormat;
            LongTimeFormat  = longTimeFormat;
            ShortTimeFormat = shortTimeFormat;

            ContextSeparator  = contextSeparator ?? DefaultContextSeparator;
            StartEndSeparator = startEndSeparator ?? DefaultStartEndSeparator;
            DurationSeparator = durationSeparator ?? DefaultDurationSeparator;

            DurationKind           = durationFormatKind;
            UseDurationSeconds     = useDurationSeconds;
            UseIsoIntervalNotation = useIsoIntervalNotation;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <paramref name="timeSpan"/>을 문자열로 표현합니다.
        /// </summary>
        public string GetDuration(TimeSpan timeSpan, DurationFormatKind? durationFormatKind) {
            switch(durationFormatKind.GetValueOrDefault(DurationFormatKind.Compact)) {
                case DurationFormatKind.Detailed:
                    var days = timeSpan.TotalDays.AsInt(0);
                    var hours = timeSpan.Hours;
                    var minutes = timeSpan.Minutes;
                    var seconds = UseDurationSeconds ? timeSpan.Seconds : 0;
                    return GetDuration(0, 0, days, hours, minutes, seconds);

                case DurationFormatKind.Compact:
                default:
                    return UseDurationSeconds
                               ? string.Format("{0}.{1:00}:{2:00}:{3:00}", timeSpan.Days, timeSpan.Hours, timeSpan.Minutes,
                                               timeSpan.Seconds)
                               : string.Format("{0}.{1:00}:{2:00}", timeSpan.Days, timeSpan.Hours, timeSpan.Minutes);
            }
        }