public void Clone(DateTimeFormatInfo format)
        {
            DateTimeFormatInfo clone = (DateTimeFormatInfo)format.Clone();

            Assert.NotSame(format, clone);

            Assert.False(clone.IsReadOnly);
            Assert.Equal(format.AbbreviatedDayNames, clone.AbbreviatedDayNames);
            Assert.Equal(format.AbbreviatedMonthGenitiveNames, clone.AbbreviatedMonthGenitiveNames);
            Assert.Equal(format.AbbreviatedMonthNames, clone.AbbreviatedMonthNames);
            Assert.Equal(format.DayNames, clone.DayNames);
            Assert.Equal(format.MonthGenitiveNames, clone.MonthGenitiveNames);
            Assert.Equal(format.MonthNames, clone.MonthNames);
            Assert.Equal(format.ShortestDayNames, clone.ShortestDayNames);

            Assert.Equal(format.AMDesignator, clone.AMDesignator);
            Assert.Equal(format.FullDateTimePattern, clone.FullDateTimePattern);
            Assert.Equal(format.LongDatePattern, clone.LongDatePattern);
            Assert.Equal(format.LongTimePattern, clone.LongTimePattern);
            Assert.Equal(format.MonthDayPattern, clone.MonthDayPattern);
            Assert.Equal(format.PMDesignator, clone.PMDesignator);
            Assert.Equal(format.RFC1123Pattern, clone.RFC1123Pattern);
            Assert.Equal(format.ShortDatePattern, clone.ShortDatePattern);
            Assert.Equal(format.ShortTimePattern, clone.ShortTimePattern);
            Assert.Equal(format.SortableDateTimePattern, clone.SortableDateTimePattern);
            Assert.Equal(format.UniversalSortableDateTimePattern, clone.UniversalSortableDateTimePattern);
            Assert.Equal(format.YearMonthPattern, clone.YearMonthPattern);
            Assert.Equal(format.CalendarWeekRule, clone.CalendarWeekRule);
            Assert.Equal(format.FirstDayOfWeek, clone.FirstDayOfWeek);
        }
예제 #2
0
        // Expand a pre-defined format string (like "D" for long date) to the real format that
        // we are going to use in the date time parsing.
        // This method also convert the dateTime if necessary (e.g. when the format is in Universal time),
        // and change dtfi if necessary (e.g. when the format should use invariant culture).
        //
        private static String ExpandPredefinedFormat(String format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi)
        {
            switch (format[0])
            {
            case 'r':
            case 'R':           // RFC 1123 Standard
//                    dateTime = dateTime.ToUniversalTime();
                dtfi = DateTimeFormatInfo.InvariantInfo;
                break;

            case 's':           // Sortable without Time Zone Info
                dtfi = DateTimeFormatInfo.InvariantInfo;
                break;

            case 'u':           // Universal time in sortable format.
//                    dateTime = dateTime.ToUniversalTime();
                // Universal time is always in Greogrian calendar.
                dtfi = DateTimeFormatInfo.InvariantInfo;
                break;

            case 'U':           // Universal time in culture dependent format.
                // Universal time is always in Greogrian calendar.
                //
                //
                dtfi = (DateTimeFormatInfo)dtfi.Clone();
                if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
                {
                    dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
                }
                dateTime = dateTime.ToUniversalTime();
                break;
            }
            format = GetRealFormat(format, dtfi);
            return(format);
        }
예제 #3
0
        public void Clone(DateTimeFormatInfo format)
        {
            DateTimeFormatInfo clone = (DateTimeFormatInfo)format.Clone();
            Assert.NotSame(format, clone);

            Assert.False(clone.IsReadOnly);
            Assert.Equal(format.AbbreviatedDayNames, clone.AbbreviatedDayNames);
            Assert.Equal(format.AbbreviatedMonthGenitiveNames, clone.AbbreviatedMonthGenitiveNames);
            Assert.Equal(format.AbbreviatedMonthNames, clone.AbbreviatedMonthNames);
            Assert.Equal(format.DayNames, clone.DayNames);
            Assert.Equal(format.MonthGenitiveNames, clone.MonthGenitiveNames);
            Assert.Equal(format.MonthNames, clone.MonthNames);
            Assert.Equal(format.ShortestDayNames, clone.ShortestDayNames);

            Assert.Equal(format.AMDesignator, clone.AMDesignator);
            Assert.Equal(format.FullDateTimePattern, clone.FullDateTimePattern);
            Assert.Equal(format.LongDatePattern, clone.LongDatePattern);
            Assert.Equal(format.LongTimePattern, clone.LongTimePattern);
            Assert.Equal(format.MonthDayPattern, clone.MonthDayPattern);
            Assert.Equal(format.PMDesignator, clone.PMDesignator);
            Assert.Equal(format.RFC1123Pattern, clone.RFC1123Pattern);
            Assert.Equal(format.ShortDatePattern, clone.ShortDatePattern);
            Assert.Equal(format.ShortTimePattern, clone.ShortTimePattern);
            Assert.Equal(format.SortableDateTimePattern, clone.SortableDateTimePattern);
            Assert.Equal(format.UniversalSortableDateTimePattern, clone.UniversalSortableDateTimePattern);
            Assert.Equal(format.YearMonthPattern, clone.YearMonthPattern);
            Assert.Equal(format.CalendarWeekRule, clone.CalendarWeekRule);
            Assert.Equal(format.FirstDayOfWeek, clone.FirstDayOfWeek);
        }
        private static string ExpandPredefinedFormat(string format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset)
        {
            switch (format[0])
            {
            case 'o':
            case 'O':
                dtfi = DateTimeFormatInfo.InvariantInfo;
                goto Label_0160;

            case 'r':
            case 'R':
                if (offset != NullOffset)
                {
                    dateTime -= offset;
                }
                else if (dateTime.Kind == DateTimeKind.Local)
                {
                    InvalidFormatForLocal(format, dateTime);
                }
                dtfi = DateTimeFormatInfo.InvariantInfo;
                goto Label_0160;

            case 's':
                dtfi = DateTimeFormatInfo.InvariantInfo;
                goto Label_0160;

            case 'u':
                if (offset == NullOffset)
                {
                    if (dateTime.Kind == DateTimeKind.Local)
                    {
                        InvalidFormatForLocal(format, dateTime);
                    }
                    break;
                }
                dateTime -= offset;
                break;

            case 'U':
                if (offset != NullOffset)
                {
                    throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
                }
                dtfi = (DateTimeFormatInfo)dtfi.Clone();
                if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
                {
                    dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
                }
                dateTime = dateTime.ToUniversalTime();
                goto Label_0160;

            default:
                goto Label_0160;
            }
            dtfi = DateTimeFormatInfo.InvariantInfo;
Label_0160:
            format = GetRealFormat(format, dtfi);
            return(format);
        }
예제 #5
0
파일: Format.cs 프로젝트: zzy092/npoi
 public SimpleDateFormat(string pattern, DateTimeFormatInfo formatSymbols)
 {
     if (pattern == null || formatSymbols == null)
     {
         throw new ArgumentNullException();
     }
     this._pattern    = pattern;
     this._formatData = (DateTimeFormatInfo)formatSymbols.Clone();
     this._culture    = CultureInfo.CurrentCulture;
 }
예제 #6
0
    public static void Main()
    {
        DateTimeFormatInfo current1 = DateTimeFormatInfo.CurrentInfo;

        current1 = (DateTimeFormatInfo)current1.Clone();
        Console.WriteLine(current1.IsReadOnly);

        CultureInfo        culture2 = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name);
        DateTimeFormatInfo current2 = culture2.DateTimeFormat;

        Console.WriteLine(current2.IsReadOnly);
    }
        // Token: 0x060015EA RID: 5610 RVA: 0x000410D8 File Offset: 0x0003F2D8
        private static string ExpandPredefinedFormat(string format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset)
        {
            char c = format[0];

            if (c != 'U')
            {
                if (c != 's')
                {
                    if (c == 'u')
                    {
                        if (offset != DateTimeFormat.NullOffset)
                        {
                            dateTime -= offset;
                        }
                        else if (dateTime.Kind == DateTimeKind.Local)
                        {
                            DateTimeFormat.InvalidFormatForLocal(format, dateTime);
                        }
                        dtfi = DateTimeFormatInfo.InvariantInfo;
                    }
                }
                else
                {
                    dtfi = DateTimeFormatInfo.InvariantInfo;
                }
            }
            else
            {
                if (offset != DateTimeFormat.NullOffset)
                {
                    throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
                }
                dtfi = (DateTimeFormatInfo)dtfi.Clone();
                if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
                {
                    dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
                }
                dateTime = dateTime.ToUniversalTime();
            }
            format = DateTimeFormat.GetRealFormat(format, dtfi);
            return(format);
        }
예제 #8
0
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3: Call Clone method on a readonly instance created from several cultures");

        try
        {
            DateTimeFormatInfo expected = CultureInfo.InvariantCulture.DateTimeFormat;
            retVal = VerificationHelper(expected, expected.Clone(), "003.1") && retVal;
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("003.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
예제 #9
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call Clone method on a instance created from Ctor");

        try
        {
            DateTimeFormatInfo expected = new DateTimeFormatInfo();

            retVal = VerificationHelper(expected, expected.Clone(), "001.1") && retVal;
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
예제 #10
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call Clone method on a instance created from Ctor");

        try
        {
            DateTimeFormatInfo expected = new DateTimeFormatInfo();

            retVal = VerificationHelper(expected, expected.Clone(), "001.1") && retVal;
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
예제 #11
0
        public void PosTest3()
        {
            DateTimeFormatInfo expected = CultureInfo.InvariantCulture.DateTimeFormat;

            VerificationHelper(expected, expected.Clone());
        }
예제 #12
0
        public void PosTest1()
        {
            DateTimeFormatInfo expected = new DateTimeFormatInfo();

            VerificationHelper(expected, expected.Clone());
        }
        internal static DateTimeFormatInfo Build(DateTimeFormatInfo original)
        {
            var persianFormats = (DateTimeFormatInfo)original.Clone();

            var persianCalendarMonthNames = new[] {
                "فروردین",
                "اردیبهشت",
                "خرداد",
                "تیر",
                "مرداد",
                "شهریور",
                "مهر",
                "آبان",
                "آذر",
                "دی",
                "بهمن",
                "اسفند",
                "" // 13 months names always necessary...
            };

            persianFormats.MonthNames =
                persianFormats.AbbreviatedMonthNames  =
                    persianFormats.MonthGenitiveNames =
                        persianFormats.AbbreviatedMonthGenitiveNames =
                            persianCalendarMonthNames;

            var persianDayNames = new[] {
                "یکشنبه", // Changes the Arabic "ي" and "ك" to the Farsi "ی" and "ک" respectively (incorrect in .NET Framework).
                "دوشنبه",
                "سه شنبه",
                "چهارشنبه",
                "پنجشنبه",
                "جمعه",
                "شنبه"
            };

            persianFormats.DayNames =
                persianFormats.AbbreviatedDayNames =
                    persianDayNames;

            persianFormats.SetAllDateTimePatterns(new[] {
                "yyyy/MM/dd",
                "yy/MM/dd",
                "yyyy/M/d",
                "yy/M/d"
            }, 'd');

            persianFormats.SetAllDateTimePatterns(new[] {
                "dddd، d MMMM yyyy",
                "d MMMM yyyy"
            }, 'D');

            persianFormats.SetAllDateTimePatterns(new[] {
                "MMMM yyyy",
                "MMMM yy"
            }, 'y');

            persianFormats.SetAllDateTimePatterns(new[] {
                "HH:mm",
                "H:mm",
                "hh:mm tt",
                "h:mm tt"
            }, 't');

            persianFormats.SetAllDateTimePatterns(new[] {
                "HH:mm:ss",
                "H:mm:ss",
                "hh:mm:ss tt",
                "h:mm:ss tt"
            }, 'T');

            return(persianFormats);
        }
예제 #14
0
        private void FormatInitializer()
        {
            var adminInfo = Company.GetCompanyService().GetAdminInfo();

            #region NumberFormatInfo

            NumberFormatInfo = new NumberFormatInfo
            {
                NumberDecimalSeparator = adminInfo.DecimalSeparator,
                NumberGroupSeparator   = adminInfo.ThousandsSeparator,
            };

            #endregion

            #region DateTimeFormatInfo

            string dateFormatPattern;

            switch (adminInfo.DateTemplate)
            {
            case BoDateTemplate.dt_DDMMYY:
                dateFormatPattern = "dd{0}MM{0}yy";
                break;

            case BoDateTemplate.dt_DDMMCCYY:
                dateFormatPattern = "dd{0}MM{0}yyyy";
                break;

            case BoDateTemplate.dt_MMDDYY:
                dateFormatPattern = "MM{0}dd{0}yy";
                break;

            case BoDateTemplate.dt_MMDDCCYY:
                dateFormatPattern = "MM{0}dd{0}yyyy";
                break;

            case BoDateTemplate.dt_CCYYMMDD:
                dateFormatPattern = "yyyy{0}MM{0}dd";
                break;

            case BoDateTemplate.dt_DDMonthYYYY:
                dateFormatPattern = "dd{0}MMMM{0}yyyy";
                break;

            default:                     // Desconhecido
                throw new InvalidOperationException("Formato de data identificado não é conhecido (AdminInfo.DateTemplate).");
            }

            var datePattern = String.Format(dateFormatPattern, adminInfo.DateSeparator);
            var timePattern = adminInfo.TimeTemplate == BoTimeTemplate.tt_24H ? "HH:mm" : "hh:mm";

            var newDateTimeFormat = (DateTimeFormatInfo)DateTimeFormatInfo.Clone();

            newDateTimeFormat.DateSeparator    = adminInfo.DateSeparator;
            newDateTimeFormat.LongDatePattern  = datePattern;
            newDateTimeFormat.ShortDatePattern = datePattern;
            newDateTimeFormat.LongTimePattern  = timePattern;
            newDateTimeFormat.ShortTimePattern = timePattern;

            DateTimeFormatInfo = newDateTimeFormat;

            #endregion
        }
예제 #15
0
        /// <summary>
        ///   Parses a string to a date time value
        /// </summary>
        /// <param name="originalValue">The original value.</param>
        /// <param name="dateFormat">The short date format.</param>
        /// <param name="dateSeparator">The date separator.</param>
        /// <param name="timeSeparator">The time separator.</param>
        /// <returns></returns>
        private static DateTime?OldStringToDateTime(string originalValue, string dateFormat, string dateSeparator,
                                                    string timeSeparator)
        {
            var stringDateValue = originalValue == null ? string.Empty : originalValue.Trim();

            if (string.IsNullOrEmpty(stringDateValue) || stringDateValue == "00000000" ||
                stringDateValue == "99999999")
            {
                return(null);
            }

            DateTime?dateFieldValue = null;

            try
            {
                var dateTimeFormats = StringUtils.SplitByDelimiter(dateFormat);

                /*
                 *       bool hasTime = (shortDateFormat.IndexOf('H') > -1) || (shortDateFormat.IndexOf('h') > -1);
                 *       bool hasDate = (shortDateFormat.IndexOf('d') > -1);
                 *
                 *      // HH:= hour as a number from 00 through 23;  FFF:= Fractions of a second (if present)
                 *      const string timeFormat = "HH:mm:ss.FFF";
                 *      List<string> dateTimeFormats = new List<string>(4);
                 *      dateTimeFormats.Add(shortDateFormat);
                 *      if (hasDate && !hasTime)
                 *        dateTimeFormats.Add(shortDateFormat + " " + timeFormat);
                 *      if (hasDate)
                 *      {
                 *        dateTimeFormats.Add(@"yyyyMMdd");
                 *        dateTimeFormats.Add(@"yyyyMMdd" + timeFormat);
                 *      }
                 */
                var dateTimeFormatInfo = new DateTimeFormatInfo();

                dateTimeFormatInfo.SetAllDateTimePatterns(dateTimeFormats, 'd');
                dateTimeFormatInfo.DateSeparator = dateSeparator;
                dateTimeFormatInfo.TimeSeparator = timeSeparator;

                // Use ParseExact since Parse does not work if a date sepertaor is set but
                // the date separator is not part of the date format
                try
                {
                    dateFieldValue = DateTime.ParseExact(stringDateValue, dateTimeFormats, dateTimeFormatInfo,
                                                         DateTimeStyles.AllowWhiteSpaces);
                    // Times get the current date added, remove it
                    //if ((!hasDate) && (dateFieldValue.Value.Date == DateTime.Now.Date))
                    //{
                    //  dateFieldValue = DateTime.MinValue.Date.Add(dateFieldValue.Value.TimeOfDay);
                    //}
                }
                catch (FormatException)
                {
                    if (dateSeparator != "/")
                    {
                        var dateTimeFormatInfoSlash = new DateTimeFormatInfo();

                        // Build a new formatter with / but otherwise the same settings
                        dateTimeFormatInfoSlash = (DateTimeFormatInfo)dateTimeFormatInfo.Clone();
                        dateTimeFormatInfoSlash.DateSeparator = "/";

                        // try with date separator of /
                        dateFieldValue = DateTime.ParseExact(stringDateValue, dateTimeFormats, dateTimeFormatInfoSlash,
                                                             DateTimeStyles.AllowWhiteSpaces);
                    }
                }
            }
            catch (Exception)
            {
                // ignoring all errors
            }

            return(dateFieldValue);
        }
예제 #16
0
 /// <summary>
 /// Returns the cloned formatting info if its desired.
 /// </summary>
 /// <returns></returns>
 public static DateTimeFormatInfo GetFormatInfo()
 {
     InitFormatInfo();
     return((DateTimeFormatInfo)FormatInfo.Clone());
 }