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);
        }
 public static string GetPMDesignator(this Culture inculture)
 {
     if (inculture == null)
     {
         inculture = Globals.CurrentCulture;
     }
     return(CalendarNames.GetAMPM(false, inculture.BaseLanguage));
 }
 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));
 }
 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);
 }
 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));
 }
 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));
 }
 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);
 }
 public static bool IsLeapYear(int year, CalendarTypes calendar)
 {
     return(CalendarNames.GetLeapYear(year, calendar));
 }
 public static int GetMonthsInYear(this int year, CalendarTypes calendar)
 {
     return(CalendarNames.GetMonthsInYear(year, calendar));
 }
Example #10
0
 public static int GetDaysInYear(int year, CalendarTypes calendar)
 {
     return(CalendarNames.GetDaysInYear(year, calendar));
 }
Example #11
0
 public static int GetDaysInMonth(int month, int year, CalendarTypes calendar)
 {
     return(CalendarNames.GetDaysInMonth(month, year, calendar));
 }