Exemple #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;
        }
Exemple #2
0
        /// <summary>
        /// <paramref name="weekOfYearRule"/> 에 따라 <paramref name="weekRule"/>과  <paramref name="firstDayOfWeek"/> 를 결정합니다.
        /// </summary>
        /// <param name="culture">문화권</param>
        /// <param name="weekOfYearRule">주차 계산을 위한 룰</param>
        /// <param name="weekRule">한해의 첫주를 산정하는 규칙</param>
        /// <param name="firstDayOfWeek">한주의 첫번째 요일</param>
        public static void GetCalendarWeekRuleAndFirstDayOfWeek(CultureInfo culture,
                                                                WeekOfYearRuleKind? weekOfYearRule,
                                                                out CalendarWeekRule weekRule,
                                                                out DayOfWeek firstDayOfWeek) {
            if(weekOfYearRule.GetValueOrDefault(WeekOfYearRuleKind.Calendar) == WeekOfYearRuleKind.Calendar) {
                weekRule = culture.GetOrCurrentCulture().DateTimeFormat.CalendarWeekRule;
                firstDayOfWeek = culture.GetOrCurrentCulture().DateTimeFormat.FirstDayOfWeek;
            }
            else {
                weekRule = CalendarWeekRule.FirstFourDayWeek;
                firstDayOfWeek = DayOfWeek.Monday;
            }

            if(IsDebugEnabled)
                log.Debug("WeekOfyearRuleKind에 따른 CalendarWeekRule, FirstDayOfWeek 정보를 결정했습니다!!! " +
                          @"culture=[{0}], weekOfYearRule=[{1}], weekRule=[{2}], firstDayOfWeek=[{3}]",
                          culture, weekOfYearRule, weekRule, firstDayOfWeek);
        }
Exemple #3
0
        /// <summary>
        /// 두 DateTime 값이 주(Week) 단위까지 같은지 판단합니다.
        /// </summary>
        public static bool IsSameWeek(this DateTime left, DateTime right, CultureInfo culture, CalendarWeekRule weekRule,
                                      DayOfWeek firstDayOfWeek, WeekOfYearRuleKind weekOfYearRuleKind) {
            culture = culture.GetOrCurrentCulture();

            var leftYearWeek = GetWeekOfYear(left, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind);
            var rightYearWeek = GetWeekOfYear(right, culture, weekRule, firstDayOfWeek, weekOfYearRuleKind);

            return Equals(leftYearWeek, rightYearWeek);
        }
Exemple #4
0
 /// <summary>
 /// 두 DateTime 값이 주(Week) 단위까지 같은지 판단합니다.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <param name="culture"></param>
 /// <param name="weekOfYearRuleKind"></param>
 /// <returns></returns>
 public static bool IsSameWeek(this DateTime left, DateTime right, CultureInfo culture, WeekOfYearRuleKind weekOfYearRuleKind) {
     culture = culture.GetOrCurrentCulture();
     return IsSameWeek(left, right, culture, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek,
                       weekOfYearRuleKind);
 }
        /// <summary>
        /// 지정한 문화권의 모든 리소스 정보를 Hashtable로 반환한다.
        /// </summary>
        public Hashtable GetResources(CultureInfo culture) {
            if(IsDebugEnabled)
                log.Debug("Get resources map... resourceType=[{0}], culture=[{1}]", ResourceName, culture);

            var resourceMap = new Hashtable();
            try {
                culture = culture.GetOrCurrentCulture();

                using(var cmd = GetResourcesCommand(culture.Name))
                using(var reader = Ado.ExecuteReader(cmd)) {
                    while(reader.Read()) {
                        var key = reader.AsString("ResourceKey");
                        var value = reader.AsString("ResourceValue");

                        resourceMap.Add(key, value);
                    }
                }
            }
            catch(Exception ex) {
                if(log.IsErrorEnabled) {
                    log.Error("리소스를 얻는데 실패했습니다. culture=[{0}]", culture);
                    log.Error(ex);
                }

                throw;
            }
            return resourceMap;
        }
Exemple #6
0
 /// <summary>
 /// 주차 계산 룰과 문화권에 따른 한주의 첫번째 요일을 구합니다.
 /// </summary>
 /// <param name="culture">문화권</param>
 /// <param name="weekOfYearRule">주차 계산 룰</param>
 /// <returns></returns>
 public static DayOfWeek GetFirstDayOfWeek(CultureInfo culture = null,
                                           WeekOfYearRuleKind? weekOfYearRule = null) {
     return weekOfYearRule.GetValueOrDefault(WeekOfYearRuleKind.Calendar) == WeekOfYearRuleKind.Iso8601
                ? DayOfWeek.Monday
                : culture.GetOrCurrentCulture().DateTimeFormat.FirstDayOfWeek;
 }
Exemple #7
0
 /// <summary>
 /// 주차 계산 룰과 문화권에 따른 주차 계산 룰을 구합니다.
 /// </summary>
 /// <param name="culture">문화권</param>
 /// <param name="weekOfYearRule">주차 계산 룰</param>
 /// <returns></returns>
 public static CalendarWeekRule GetCalendarWeekRule(CultureInfo culture = null,
                                                    WeekOfYearRuleKind? weekOfYearRule = null) {
     return weekOfYearRule.GetValueOrDefault(WeekOfYearRuleKind.Calendar) == WeekOfYearRuleKind.Iso8601
                ? CalendarWeekRule.FirstFourDayWeek
                : culture.GetOrCurrentCulture().DateTimeFormat.CalendarWeekRule;
 }