Ejemplo n.º 1
0
        internal static string GetDateTimeStr(string format     = "",
                                              DateTime?dt       = null,
                                              Culture cul       = null,
                                              CalendarTypes?cal = null)
        {
            if (!dt.HasValue)
            {
                return("");
            }
            if ((dt > _max) || (dt < _min))
            {
                throw new ArgumentOutOfRangeException("dt",
                                                      "Your DateTime (" + dt.Value.Year + "-" + dt.Value.Month + "-" +
                                                      dt.Value.Day +
                                                      ") exceeds the supported range, max=" + MaxDateSupported.Year +
                                                      "-" +
                                                      MaxDateSupported.Month + "-" + MaxDateSupported.Day + " min=" +
                                                      MinDateSupported.Year + "-" + MinDateSupported.Month + "-" +
                                                      MinDateSupported.Day);
            }
            //if (caltype == null) caltype = this.Calendar;
            if (cul == null)
            {
                cul = Globals.CurrentCulture;
            }
            if (cal == null)
            {
                cal = cul.Calendar;
            }
            if (format == "")
            {
                format = cul.DateTimeFormat;
            }
            int year, month, day, hour, min, sec, mil;

            ConvertToCalendar((DateTime)dt, out year, out month, out day, out hour, out min, out sec, out mil, cal);
            DayOfWeek dow     = ((DateTime)dt).DayOfWeek;
            string    dwname  = GetDayName(dow, false, cul);
            string    dwshort = GetDayName(dow, true, cul);
            string    mnname  = GetMonthName(month, false, cal, cul);
            string    mnshort = GetMonthName(month, true, cal, cul);
            string    ampm    = (((hour >= 12) || (hour == 24)) ? GetPMDesignator(cul) : GetAMDesignator(cul));
            string    str     = CalendarNames.FormattedString(year,
                                                              month,
                                                              day,
                                                              hour,
                                                              min,
                                                              sec,
                                                              mil,
                                                              dow,
                                                              mnname,
                                                              mnshort,
                                                              dwname,
                                                              dwshort,
                                                              ampm,
                                                              format);

            return(str);
        }
Ejemplo n.º 2
0
 public static string GetPMDesignator(this Culture inculture)
 {
     if (inculture == null)
     {
         inculture = Globals.CurrentCulture;
     }
     return(CalendarNames.GetAMPM(false, inculture.BaseLanguage));
 }
Ejemplo n.º 3
0
 public static string GetDayName(this DayOfWeek dow, bool shorten = false, Culture inculture = null)
 {
     if (inculture == null)
     {
         inculture = Globals.CurrentCulture;
     }
     return(CalendarNames.GetDayOfWeekName(dow, inculture.BaseLanguage, shorten));
 }
Ejemplo n.º 4
0
 public static DateTime MoveToSupportRange(this DateTime dt)
 {
     foreach (CalendarTypes calendarType in Enum.GetValues(typeof(CalendarTypes)))
     {
         if (dt < CalendarNames.GetCalendar(calendarType).MinSupportedDateTime)
         {
             dt = CalendarNames.GetCalendar(calendarType).MinSupportedDateTime;
         }
         if (dt > CalendarNames.GetCalendar(calendarType).MaxSupportedDateTime)
         {
             dt = CalendarNames.GetCalendar(calendarType).MaxSupportedDateTime;
         }
     }
     return(dt);
 }
Ejemplo n.º 5
0
 public static string GetMonthName(int month,
                                   bool shorten          = false,
                                   CalendarTypes?caltype = null,
                                   Culture inculture     = null)
 {
     if (inculture == null)
     {
         inculture = Globals.CurrentCulture;
     }
     if (caltype == null)
     {
         caltype = inculture.Calendar;
     }
     return(CalendarNames.GetMonthName(month, (CalendarTypes)caltype, inculture.BaseLanguage, shorten));
 }
Ejemplo n.º 6
0
 public static DateTime ConvertFromCalendar(int year,
                                            int month,
                                            int day,
                                            int hour,
                                            int min,
                                            int sec,
                                            int milli,
                                            CalendarTypes?caltype = null)
 {
     if (caltype == null)
     {
         caltype = Globals.CurrentCulture.Calendar;
     }
     return(CalendarNames.GetDateTime(year, month, day, hour, min, sec, milli, (CalendarTypes)caltype));
 }
Ejemplo n.º 7
0
 public static void ConvertToCalendar(this DateTime dt,
                                      out int year,
                                      out int month,
                                      out int day,
                                      out int hour,
                                      out int min,
                                      out int sec,
                                      out int milli,
                                      CalendarTypes?caltype = null)
 {
     if (caltype == null)
     {
         caltype = Globals.CurrentCulture.Calendar;
     }
     CalendarNames.FromDateTime(dt,
                                (CalendarTypes)caltype,
                                out year,
                                out month,
                                out day,
                                out hour,
                                out min,
                                out sec,
                                out milli);
 }
Ejemplo n.º 8
0
 public static bool IsLeapYear(int year, CalendarTypes calendar)
 {
     return(CalendarNames.GetLeapYear(year, calendar));
 }
Ejemplo n.º 9
0
 public static int GetMonthsInYear(this int year, CalendarTypes calendar)
 {
     return(CalendarNames.GetMonthsInYear(year, calendar));
 }
Ejemplo n.º 10
0
 public static int GetDaysInYear(int year, CalendarTypes calendar)
 {
     return(CalendarNames.GetDaysInYear(year, calendar));
 }
Ejemplo n.º 11
0
 public static int GetDaysInMonth(int month, int year, CalendarTypes calendar)
 {
     return(CalendarNames.GetDaysInMonth(month, year, calendar));
 }