public void IsLeapMonth(int year, int month)
 {
     GregorianCalendar calendar = new GregorianCalendar();
     Assert.False(calendar.IsLeapMonth(year, month));
     Assert.False(calendar.IsLeapMonth(year, month, 0));
     Assert.False(calendar.IsLeapMonth(year, month, 1));
 }
 public void IsLeapDay(int year, int month, int day)
 {
     ThaiBuddhistCalendar calendar = new ThaiBuddhistCalendar();
     bool expected = new GregorianCalendar().IsLeapDay(year, month, day);
     Assert.Equal(expected, new ThaiBuddhistCalendar().IsLeapDay(year + 543, month, day));
     Assert.Equal(expected, new ThaiBuddhistCalendar().IsLeapDay(year + 543, month, day, 0));
     Assert.Equal(expected, new ThaiBuddhistCalendar().IsLeapDay(year + 543, month, day, 1));
 }
 public void IsLeapYearTest(int year)
 {
     GregorianCalendar calendar = new GregorianCalendar();
     bool expected = IsLeapYear(year);
     Assert.Equal(expected, calendar.IsLeapYear(year));
     Assert.Equal(expected, calendar.IsLeapYear(year, 0));
     Assert.Equal(expected, calendar.IsLeapYear(year, 1));
 }
 public void IsLeapDay(int year, int month, int day)
 {
     GregorianCalendar calendar = new GregorianCalendar();
     bool expected = IsLeapYear(year) && month == 2 && day == 29;
     Assert.Equal(expected, calendar.IsLeapDay(year, month, day));
     Assert.Equal(expected, calendar.IsLeapDay(year, month, day, 0));
     Assert.Equal(expected, calendar.IsLeapDay(year, month, day, 1));
 }
 public void TestGregorianCalendar() {
    GregorianCalendar date = new GregorianCalendar();
    GregorianCalendarTransform format = new GregorianCalendarTransform();
    date.setTime(new Date());
    String value = format.write(date);
    GregorianCalendar copy = format.read(value);
    AssertEquals(date, copy);
 }
 public void GetDaysInMonth(int year, int month)
 {
     KoreanCalendar calendar = new KoreanCalendar();
     int expected = new GregorianCalendar().GetDaysInMonth(year, month);
     Assert.Equal(expected, calendar.GetDaysInMonth(year + 2333, month));
     Assert.Equal(expected, calendar.GetDaysInMonth(year + 2333, month, 0));
     Assert.Equal(expected, calendar.GetDaysInMonth(year + 2333, month, 1));
 }
 public void GetDaysInMonth(int year, int month)
 {
     ThaiBuddhistCalendar calendar = new ThaiBuddhistCalendar();
     int expected = new GregorianCalendar().GetDaysInMonth(year, month);
     Assert.Equal(expected, calendar.GetDaysInMonth(year + 543, month));
     Assert.Equal(expected, calendar.GetDaysInMonth(year + 543, month, 0));
     Assert.Equal(expected, calendar.GetDaysInMonth(year + 543, month, 1));
 }
 public void IsLeapYear(int year)
 {
     KoreanCalendar calendar = new KoreanCalendar();
     bool expected = new GregorianCalendar().IsLeapYear(year);
     Assert.Equal(expected, calendar.IsLeapYear(year + 2333));
     Assert.Equal(expected, calendar.IsLeapYear(year + 2333, 0));
     Assert.Equal(expected, calendar.IsLeapYear(year + 2333, 1));
 }
 public void GetMonthsInYear(int year)
 {
     GregorianCalendar calendar = new GregorianCalendar();
     int expected = 12;
     Assert.Equal(expected, calendar.GetMonthsInYear(year));
     Assert.Equal(expected, calendar.GetMonthsInYear(year, 0));
     Assert.Equal(expected, calendar.GetMonthsInYear(year, 1));
 }
 public void IsLeapYear(int year)
 {
     TaiwanCalendar calendar = new TaiwanCalendar();
     bool expected = new GregorianCalendar().IsLeapYear(year + 1911);
     Assert.Equal(expected, calendar.IsLeapYear(year));
     Assert.Equal(expected, calendar.IsLeapYear(year, 0));
     Assert.Equal(expected, calendar.IsLeapYear(year, 1));
 }
 public void GetDaysInYear(int year)
 {
     KoreanCalendar calendar = new KoreanCalendar();
     int expected = new GregorianCalendar().GetDaysInYear(year);
     Assert.Equal(expected, calendar.GetDaysInYear(year + 2333));
     Assert.Equal(expected, calendar.GetDaysInYear(year + 2333, 0));
     Assert.Equal(expected, calendar.GetDaysInYear(year + 2333, 1));
 }
 public void GetMonthsInYear(int year)
 {
     ThaiBuddhistCalendar calendar = new ThaiBuddhistCalendar();
     int expected = new GregorianCalendar().GetMonthsInYear(year);
     Assert.Equal(expected, calendar.GetMonthsInYear(year + 543));
     Assert.Equal(expected, calendar.GetMonthsInYear(year + 543, 0));
     Assert.Equal(expected, calendar.GetMonthsInYear(year + 543, 1));
 }
 public void IsLeapYear(int year)
 {
     ThaiBuddhistCalendar calendar = new ThaiBuddhistCalendar();
     bool expected = new GregorianCalendar().IsLeapYear(year);
     Assert.Equal(expected, calendar.IsLeapYear(year + 543));
     Assert.Equal(expected, calendar.IsLeapYear(year + 543, 0));
     Assert.Equal(expected, calendar.IsLeapYear(year + 543, 1));
 }
 public void ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
 {
     GregorianCalendar calendar = new GregorianCalendar();
     DateTime expected = new DateTime(year, month, day, hour, minute, second, millisecond);
     Assert.Equal(expected, calendar.ToDateTime(year, month, day, hour, minute, second, millisecond));
     Assert.Equal(expected, calendar.ToDateTime(year, month, day, hour, minute, second, millisecond, 0));
     Assert.Equal(expected, calendar.ToDateTime(year, month, day, hour, minute, second, millisecond, 1));
 }
 public void GetDaysInMonth(int year, int month)
 {
     GregorianCalendar calendar = new GregorianCalendar();
     int expected = IsLeapYear(year) ? s_daysInMonthInLeapYear[month] : s_daysInMonthInCommonYear[month];
     Assert.Equal(expected, calendar.GetDaysInMonth(year, month));
     Assert.Equal(expected, calendar.GetDaysInMonth(year, month, 0));
     Assert.Equal(expected, calendar.GetDaysInMonth(year, month, 1));
 }
 public void IsLeapDay(int year, int month, int day)
 {
     KoreanCalendar calendar = new KoreanCalendar();
     bool expected = new GregorianCalendar().IsLeapDay(year, month, day);
     Assert.Equal(expected, calendar.IsLeapDay(year + 2333, month, day));
     Assert.Equal(expected, calendar.IsLeapDay(year + 2333, month, day, 0));
     Assert.Equal(expected, calendar.IsLeapDay(year + 2333, month, day, 1));
 }
 public void IsLeapMonth(int year, int month)
 {
     KoreanCalendar calendar = new KoreanCalendar();
     bool expected = new GregorianCalendar().IsLeapMonth(year, month);
     Assert.Equal(expected, calendar.IsLeapMonth(year + 2333, month));
     Assert.Equal(expected, calendar.IsLeapMonth(year + 2333, month, 0));
     Assert.Equal(expected, calendar.IsLeapMonth(year + 2333, month, 1));
 }
 public void GetDaysInYear(int year)
 {
     GregorianCalendar calendar = new GregorianCalendar();
     int expected = IsLeapYear(year) ? 366 : 365;
     Assert.Equal(expected, calendar.GetDaysInYear(year));
     Assert.Equal(expected, calendar.GetDaysInYear(year, 0));
     Assert.Equal(expected, calendar.GetDaysInYear(year, 1));
 }
 public void IsLeapMonth(int year, int month)
 {
     ThaiBuddhistCalendar calendar = new ThaiBuddhistCalendar();
     bool expected = new GregorianCalendar().IsLeapMonth(year, month);
     Assert.Equal(expected, calendar.IsLeapMonth(year + 543, month));
     Assert.Equal(expected, calendar.IsLeapMonth(year + 543, month, 0));
     Assert.Equal(expected, calendar.IsLeapMonth(year + 543, month, 1));
 }
        public void ToFourDigitYear(GregorianCalendarTypes calendarType)
        {
            Calendar calendar = new GregorianCalendar(calendarType);
            Assert.Equal(DefaultTwoDigitMax, calendar.TwoDigitYearMax);

            int randomTwoDigitYearMax = MinTwoDigitYear + s_randomDataGenerator.GetInt32(-55) % (MaxYear - MinTwoDigitYear + 1);
            calendar.TwoDigitYearMax = randomTwoDigitYearMax;
            Assert.Equal(randomTwoDigitYearMax, calendar.TwoDigitYearMax);
        }
        public void Calendar_Set()
        {
            Calendar newCalendar = new GregorianCalendar(GregorianCalendarTypes.Localized);
            var format = new DateTimeFormatInfo();
            format.Calendar = newCalendar;
            Assert.Equal(newCalendar, format.Calendar);

            format.Calendar = newCalendar;
            Assert.Equal(newCalendar, format.Calendar);
        }
 internal int GetWeekOfYearFirstDay(DateTime time, int firstDayOfWeek)
 {
     Calendar gc = new GregorianCalendar();
     // Make the day of year to be 0-based, so that 1/1 is day 0.
     int dayOfYear = gc.GetDayOfYear(time) - 1;
     // Calculate the day of week for the first day of the year.
     // dayOfWeek - (dayOfYear % 7) is the day of week for the first day of this year.  Note that
     // this value can be less than 0.  It's fine since we are making it positive again in calculating offset.
     int dayForJan1 = (int)gc.GetDayOfWeek(time) - (dayOfYear % 7);
     int offset = (dayForJan1 - firstDayOfWeek + 14) % 7;
     return (dayOfYear + offset) / 7 + 1;
 }
Beispiel #23
0
    public Dates()
    {
        cur = HttpContext.Current;

        arCul = new CultureInfo("ar-SA");
        enCul = new CultureInfo("en-US");

        h = new HijriCalendar();
        g = new GregorianCalendar(GregorianCalendarTypes.USEnglish);

        arCul.DateTimeFormat.Calendar = h;
    }
        private int GetWeekOfYearFullDays(DateTime time, CalendarWeekRule rule, int firstDayOfWeek, int fullDays)
        {
            GregorianCalendar gregorianCalendar = new GregorianCalendar();
            // Make the day of year to be 0-based, so that 1/1 is day 0.
            int dayOfYear = gregorianCalendar.GetDayOfYear(time) - 1; 
            //
            // Calculate the number of days between the first day of year (1/1) and the first day of the week.
            // This value will be a positive value from 0 ~ 6.  We call this value as "offset".
            //
            // If offset is 0, it means that the 1/1 is the start of the first week.
            //     Assume the first day of the week is Monday, it will look like this:
            //     Sun      Mon     Tue     Wed     Thu     Fri     Sat
            //     12/31    1/1     1/2     1/3     1/4     1/5     1/6
            //              +--> First week starts here.
            //
            // If offset is 1, it means that the first day of the week is 1 day ahead of 1/1.
            //     Assume the first day of the week is Monday, it will look like this:
            //     Sun      Mon     Tue     Wed     Thu     Fri     Sat
            //     1/1      1/2     1/3     1/4     1/5     1/6     1/7
            //              +--> First week starts here.
            //
            // If offset is 2, it means that the first day of the week is 2 days ahead of 1/1.
            //     Assume the first day of the week is Monday, it will look like this:
            //     Sat      Sun     Mon     Tue     Wed     Thu     Fri     Sat
            //     1/1      1/2     1/3     1/4     1/5     1/6     1/7     1/8
            //                      +--> First week starts here.

            // Day of week is 0-based.
            // Get the day of week for 1/1.  This can be derived from the day of week of the target day.
            // Note that we can get a negative value.  It's ok since we are going to make it a positive value when calculating the offset.
            int dayForJan1 = (int)gregorianCalendar.GetDayOfWeek(time) - (dayOfYear % 7);

            // Now, calculate the offset.  Subtract the first day of week from the dayForJan1.  And make it a positive value.
            int offset = (firstDayOfWeek - dayForJan1 + 14) % 7;
            if (offset != 0 && offset >= fullDays)
            {
                // If the offset is greater than the value of fullDays, it means that
                // the first week of the year starts on the week where Jan/1 falls on.
                offset -= 7;
            }
            // Calculate the day of year for specified time by taking offset into account.
            int day = dayOfYear - offset;
            if (day >= 0)
            {
                // If the day of year value is greater than zero, get the week of year.
                return (day / 7 + 1);
            }

            // Otherwise, the specified time falls on the week of previous year.
            // Call this method again by passing the last day of previous year.
            return GetWeekOfYearFullDays(time.AddDays(-(dayOfYear + 1)), rule, firstDayOfWeek, fullDays);
        }
Beispiel #25
0
    public Meetup(int month, int year)
    {
        _date = new DateTime(year, month, 1);
        var daysInMonth = new GregorianCalendar().GetDaysInMonth(year, month);

        _indexes = new Dictionary<Schedule, int[]>
        {
            {Schedule.Teenth, new[] {13, 20}},
            {Schedule.First, GetWeekBoundariesForWeek(1)},
            {Schedule.Second, GetWeekBoundariesForWeek(2)},
            {Schedule.Third, GetWeekBoundariesForWeek(3)},
            {Schedule.Fourth, GetWeekBoundariesForWeek(4)},
            {Schedule.Last, new[] {daysInMonth - 6, daysInMonth}}
        };
    }
        private PDDocumentCatalog makeDocPDFA3compliant(String producer,
                                                        String creator, bool attachZugferdHeaders)
        {
            String fullProducer = producer + " (via mustangproject.org "
                                  + versionStr + ")";

            PDDocumentCatalog cat      = doc.getDocumentCatalog();
            PDMetadata        metadata = new PDMetadata(doc);

            cat.setMetadata(metadata);
            // we're using the jempbox org.apache.jempbox.xmp.XMPMetadata version,
            // not the xmpbox one
            XMPMetadata xmp = new XMPMetadata();

            XMPSchemaPDFAId pdfaid = new XMPSchemaPDFAId(xmp);

            pdfaid.setAbout(""); //$NON-NLS-1$
            xmp.addSchema(pdfaid);

            XMPSchemaDublinCore dc = xmp.addDublinCoreSchema();

            dc.addCreator(creator);
            dc.setAbout(""); //$NON-NLS-1$

            XMPSchemaBasic xsb = xmp.addBasicSchema();

            xsb.setAbout(""); //$NON-NLS-1$

            xsb.setCreatorTool(creator);
            xsb.setCreateDate(GregorianCalendar.getInstance());
            // PDDocumentInformation pdi=doc.getDocumentInformation();
            PDDocumentInformation pdi = new PDDocumentInformation();

            pdi.setProducer(fullProducer);
            pdi.setAuthor(creator);
            doc.setDocumentInformation(pdi);

            XMPSchemaPDF pdf = xmp.addPDFSchema();

            pdf.setProducer(fullProducer);
            pdf.setAbout(""); //$NON-NLS-1$

            /*
             * // Mandatory: PDF/A3-a is tagged PDF which has to be expressed using
             * a // MarkInfo dictionary (PDF A/3 Standard sec. 6.7.2.2) PDMarkInfo
             * markinfo = new PDMarkInfo(); markinfo.setMarked(true);
             * doc.getDocumentCatalog().setMarkInfo(markinfo);
             */
            /*
             *
             * To be on the safe side, we use level B without Markinfo because we
             * can not guarantee that the user correctly tagged the templates for
             * the PDF.
             */
            pdfaid.setConformance(conformanceLevel);//$NON-NLS-1$ //$NON-NLS-1$

            pdfaid.setPart(new java.lang.Integer(3));

            if (attachZugferdHeaders)
            {
                addZugferdXMP(xmp); /*
                                     * this is the only line where we do something
                                     * Zugferd-specific, i.e. add PDF metadata
                                     * specifically for Zugferd, not generically for
                                     * a embedded file
                                     */
            }

            metadata.importXMPMetadata(xmp);
            return(cat);
        }
Beispiel #27
0
        //
        // Return the (numberOfSunday)th day of week in a particular year/month.
        //
        private static DateTime GetDayOfWeek(int year, bool fixedDate, int month, int targetDayOfWeek, int numberOfSunday, int hour, int minute, int second, int millisecond)
        {
            DateTime time;

            if (fixedDate)
            {
                //
                // Create a Fixed-Date transition time based on the supplied parameters
                // For Fixed-Dated transition times, the 'numberOfSunday' parameter actually
                // represents the day of the month.
                //

                // if the day is out of range for the month then use the last day of the month
                int day = DateTime.DaysInMonth(year, month);

                time = new DateTime(year, month, (day < numberOfSunday) ? day : numberOfSunday,
                                    hour, minute, second, millisecond, DateTimeKind.Local);
            }
            else if (numberOfSunday <= 4)
            {
                //
                // Get the (numberOfSunday)th Sunday.
                //

                time = new DateTime(year, month, 1, hour, minute, second, millisecond, DateTimeKind.Local);

                int dayOfWeek = (int)time.DayOfWeek;
                int delta     = targetDayOfWeek - dayOfWeek;
                if (delta < 0)
                {
                    delta += 7;
                }
                delta += 7 * (numberOfSunday - 1);

                if (delta > 0)
                {
                    time = time.AddDays(delta);
                }
            }
            else
            {
                //
                // If numberOfSunday is greater than 4, we will get the last sunday.
                //
                Calendar cal = GregorianCalendar.GetDefaultInstance();
                time = new DateTime(year, month, cal.GetDaysInMonth(year, month), hour, minute, second, millisecond, DateTimeKind.Local);
                // This is the day of week for the last day of the month.
                int dayOfWeek = (int)time.DayOfWeek;
                int delta     = dayOfWeek - targetDayOfWeek;
                if (delta < 0)
                {
                    delta += 7;
                }

                if (delta > 0)
                {
                    time = time.AddDays(-delta);
                }
            }
            return(time);
        }
        /**
         * Embeds an external file (generic - any type allowed) in the PDF.
         *
         * @param doc
         *            PDDocument to attach the file to.
         * @param filename
         *            name of the file that will become attachment name in the PDF
         * @param relationship
         *            how the file relates to the content, e.g. "Alternative"
         * @param description
         *            Human-readable description of the file content
         * @param subType
         *            type of the data e.g. could be "text/xml" - mime like
         * @param data
         *            the binary data of the file/attachment
         */
        public void PDFAttachGenericFile(PDDocument doc, String filename,
                                         String relationship, String description, String subType, byte[] data)
        {
            PDComplexFileSpecification fs = new PDComplexFileSpecification();

            fs.setFile(filename);

            COSDictionary dict = fs.getCOSDictionary();

            dict.setName("AFRelationship", relationship);
            dict.setString("UF", filename);
            dict.setString("Desc", description);

            ByteArrayInputStream fakeFile = new ByteArrayInputStream(data);
            PDEmbeddedFile       ef       = new PDEmbeddedFile(doc, fakeFile);

            ef.setSubtype(subType);
            ef.setSize(data.Length);
            ef.setCreationDate(new GregorianCalendar());

            ef.setModDate(GregorianCalendar.getInstance());

            fs.setEmbeddedFile(ef);

            // In addition make sure the embedded file is set under /UF
            dict = fs.getCOSDictionary();
            COSDictionary efDict = (COSDictionary)dict
                                   .getDictionaryObject(COSName.EF);
            COSBase lowerLevelFile = efDict.getItem(COSName.F);

            efDict.setItem(COSName.UF, lowerLevelFile);

            // now add the entry to the embedded file tree and set in the document.
            PDDocumentNameDictionary names = new PDDocumentNameDictionary(
                doc.getDocumentCatalog());
            PDEmbeddedFilesNameTreeNode efTree = names.getEmbeddedFiles();

            if (efTree == null)
            {
                efTree = new PDEmbeddedFilesNameTreeNode();
            }

            //Map<String, COSObjectable> namesMap = new HashMap<String, COSObjectable>();
            //      Map<String, COSObjectable> oldNamesMap = efTree.getNames();
            //if (oldNamesMap != null) {
            // for (String key : oldNamesMap.keySet()) {
            //  namesMap.put(key, oldNamesMap.get(key));
            // }
            //}
            //efTree.setNames(namesMap);
            //should be ported more exactly...
            efTree.setNames(Collections.singletonMap(filename, fs));

            names.setEmbeddedFiles(efTree);
            doc.getDocumentCatalog().setNames(names);

            // AF entry (Array) in catalog with the FileSpec
            COSArray cosArray = (COSArray)doc.getDocumentCatalog()
                                .getCOSDictionary().getItem("AF");

            if (cosArray == null)
            {
                cosArray = new COSArray();
            }
            cosArray.add(fs);
            COSDictionary dict2 = doc.getDocumentCatalog().getCOSDictionary();
            COSArray      array = new COSArray();

            array.add(fs.getCOSDictionary()); // see below
            dict2.setItem("AF", array);
            doc.getDocumentCatalog().getCOSDictionary().setItem("AF", cosArray);
        }
 public void IsLeapMonth(int year, int month, int era)
 {
     bool expected = new GregorianCalendar().IsLeapMonth(year, month, era);
     Assert.Equal(expected, new ThaiBuddhistCalendar().IsLeapMonth(year + 543, month, era));
 }
Beispiel #30
0
        /// <summary>
        /// 获取指定日所在周
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static int GetWeekOfYear(this DateTime dateTime)
        {
            GregorianCalendar calendar = new GregorianCalendar(GregorianCalendarTypes.Localized);

            return(calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Monday));
        }
Beispiel #31
0
    private Boolean DoThings()
    {
        int          iCountErrors    = 0;
        int          iCountTestcases = 0;
        String       temp;
        String       line;
        StringReader table;
        String       fileName;

        String[] values;
        Boolean  firstLine;
        Boolean  pass;
        String   format;

        String[]        expectedValues;
        CultureInfo[]   cultures;
        ResourceManager manager;
        Calendar        otherCalendar;
        Calendar        gregorian;
        Hashtable       calendars;

        calendars = new Hashtable();
        calendars.Add(0x0401, new HijriCalendar());
        calendars.Add(0x0404, new TaiwanCalendar());
        calendars.Add(0x040D, new HebrewCalendar());
        calendars.Add(0x0411, new JapaneseCalendar());
        calendars.Add(0x0412, new KoreanCalendar());
        calendars.Add(0x041E, new ThaiBuddhistCalendar());
        otherCalendar = null;
        gregorian     = new GregorianCalendar();
        pass          = true;
        try{
            manager = new ResourceManager(resourceBaseName, this.GetType().Assembly, null);
        }catch (Exception) {
            throw new Exception("ResourceFileNotFound");
        }
        if (manager == null)
        {
            throw new Exception("ResourceFileNotFound");
        }
        iCountTestcases++;
        cultures = (CultureInfo[])manager.GetObject(resCultures);
        foreach (CultureInfo culture in cultures)
        {
            if (calendars.ContainsKey(culture.LCID))
            {
                otherCalendar = (Calendar)calendars[culture.LCID];
            }
            fileName = baseFileName + fileFormalFormats + culture.ToString() + false.ToString();
            if (verbose)
            {
                Console.WriteLine("Processing formal Formatting with Gregorian, FileName - <{0}>", fileName);
            }
            temp = manager.GetString(fileName);
            if (temp == null)
            {
                throw new Exception(String.Format("Formatting table for {0} locale not found", culture.ToString()));
            }
            culture.DateTimeFormat.Calendar = gregorian;
            table     = new StringReader(temp);
            firstLine = false;
            while (true)
            {
                line = table.ReadLine();
                if (line == null)
                {
                    break;
                }
                values = line.Split(new Char[] { separator[0] });
                if (!firstLine)
                {
                    if (values[values.Length - 1] == String.Empty)
                    {
                        dateTable = new DateTime[values.Length - 2];
                    }
                    else
                    {
                        dateTable = new DateTime[values.Length - 1];
                    }
                    for (int i = 0; i < dateTable.Length; i++)
                    {
                        dateTable[i] = DateTime.ParseExact(values[i + 1], "G", culture);
                    }
                    firstLine = true;
                }
                else
                {
                    format = values[0].Trim();
                    if (values[values.Length - 1] == String.Empty)
                    {
                        expectedValues = new String[values.Length - 2];
                    }
                    else
                    {
                        expectedValues = new String[values.Length - 1];
                    }
                    for (int i = 0; i < expectedValues.Length; i++)
                    {
                        expectedValues[i] = values[i + 1];
                    }
                    for (int i = 0; i < dateTable.Length; i++)
                    {
                        if (verbose)
                        {
                            Console.WriteLine("Date: <{0}>, Format: <{1}>, Expected: <{2}>", dateTable[i], format, expectedValues[i]);
                        }
                        if (!dateTable[i].ToString(format, culture).Equals(expectedValues[i]))
                        {
                            pass = false;
                            Console.WriteLine("Err_#45232! Date: <{0}>, Format: <{1}>, Expected: <{2}>, Returned: <{3}>", dateTable[i], format, expectedValues[i], dateTable[i].ToString(format, culture));
                        }
                    }
                }
            }
            table.Close();
            fileName = baseFileName + fileFormalFormats + culture.ToString() + true.ToString();
            temp     = manager.GetString(fileName);
            if (temp != null)
            {
                if (culture.LCID == 0x040D)
                {
                    break;
                }
                if (verbose)
                {
                    Console.WriteLine("Processing formal Formatting with other otherCalendar, FileName - <{0}>", fileName);
                }
                culture.DateTimeFormat.Calendar = otherCalendar;
                table     = new StringReader(temp);
                firstLine = false;
                while (true)
                {
                    line = table.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    values = line.Split(new Char[] { separator[0] });
                    if (!firstLine)
                    {
                        if (values[values.Length - 1] == String.Empty)
                        {
                            dateTable = new DateTime[values.Length - 2];
                        }
                        else
                        {
                            dateTable = new DateTime[values.Length - 1];
                        }
                        for (int i = 0; i < dateTable.Length; i++)
                        {
                            dateTable[i] = DateTime.ParseExact(values[i + 1], "G", culture);
                        }
                        firstLine = true;
                    }
                    else
                    {
                        format = values[0].Trim();
                        if (values[values.Length - 1] == String.Empty)
                        {
                            expectedValues = new String[values.Length - 2];
                        }
                        else
                        {
                            expectedValues = new String[values.Length - 1];
                        }
                        for (int i = 0; i < expectedValues.Length; i++)
                        {
                            expectedValues[i] = values[i + 1];
                        }
                        for (int i = 0; i < dateTable.Length; i++)
                        {
                            if (verbose)
                            {
                                Console.WriteLine("Date: <{0}>, Format: <{1}>, Expected: <{2}>", dateTable[i], format, expectedValues[i]);
                            }
                            if (!dateTable[i].ToString(format, culture).Equals(expectedValues[i]))
                            {
                                pass = false;
                                Console.WriteLine("Err_20735rd! Date: <{0}>, Format: <{1}>, Expected: <{2}>, Returned: <{3}>", dateTable[i], format, expectedValues[i], dateTable[i].ToString(format, culture));
                            }
                        }
                    }
                }
                table.Close();
            }
            fileName = baseFileName + fileDateTimePatterns + culture.ToString() + false.ToString();
            if (verbose)
            {
                Console.WriteLine("Processing patterned Formatting, FileName - <{0}>", fileName);
            }
            temp = manager.GetString(fileName);
            if (temp == null)
            {
                throw new Exception(String.Format("Formatting table for {0} locale not found", culture.ToString()));
            }
            culture.DateTimeFormat.Calendar = gregorian;
            table     = new StringReader(temp);
            firstLine = false;
            while (true)
            {
                line = table.ReadLine();
                if (line == null)
                {
                    break;
                }
                if (line.Trim() == String.Empty)
                {
                    continue;
                }
                values = line.Split(new Char[] { separator[0] });
                if (!firstLine)
                {
                    if (values[values.Length - 1] == String.Empty)
                    {
                        dateTable = new DateTime[values.Length - 2];
                    }
                    else
                    {
                        dateTable = new DateTime[values.Length - 1];
                    }
                    for (int i = 0; i < dateTable.Length; i++)
                    {
                        dateTable[i] = DateTime.Parse(values[i + 1], culture);
                    }
                    firstLine = true;
                }
                else
                {
                    format = values[0];
                    if (values[values.Length - 1] == String.Empty)
                    {
                        expectedValues = new String[values.Length - 2];
                    }
                    else
                    {
                        expectedValues = new String[values.Length - 1];
                    }
                    for (int i = 0; i < expectedValues.Length; i++)
                    {
                        expectedValues[i] = values[i + 1];
                    }
                    for (int i = 0; i < dateTable.Length; i++)
                    {
                        if (verbose)
                        {
                            Console.WriteLine("Date: <{0}>, Format: <{1}>, Expected: <{2}>", dateTable[i], format, expectedValues[i]);
                        }
                        if (!dateTable[i].ToString(format, culture).Equals(expectedValues[i]))
                        {
                            pass = false;
                            Console.WriteLine("Err_385sdg! DateTime: <{0}>, Format: <{1}>, Expected: <{2}>, Returned: <{3}>", dateTable[i], format, expectedValues[i], dateTable[i].ToString(format, culture));
                        }
                    }
                }
            }
            table.Close();
            fileName = baseFileName + fileDateTimePatterns + culture.ToString() + true.ToString();
            temp     = manager.GetString(fileName);
            if (temp != null)
            {
                if (culture.LCID == 0x040D)
                {
                    break;
                }
                if (verbose)
                {
                    Console.WriteLine("Processing formal Formatting with other otherCalendar, FileName - <{0}>", fileName);
                }
                culture.DateTimeFormat.Calendar = otherCalendar;
                table     = new StringReader(temp);
                firstLine = false;
                while (true)
                {
                    line = table.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    values = line.Split(new Char[] { separator[0] });
                    if (!firstLine)
                    {
                        if (values[values.Length - 1] == String.Empty)
                        {
                            dateTable = new DateTime[values.Length - 2];
                        }
                        else
                        {
                            dateTable = new DateTime[values.Length - 1];
                        }
                        for (int i = 0; i < dateTable.Length; i++)
                        {
                            dateTable[i] = DateTime.ParseExact(values[i + 1], "G", culture);
                        }
                        firstLine = true;
                    }
                    else
                    {
                        format = values[0];
                        if (values[values.Length - 1] == String.Empty)
                        {
                            expectedValues = new String[values.Length - 2];
                        }
                        else
                        {
                            expectedValues = new String[values.Length - 1];
                        }
                        for (int i = 0; i < expectedValues.Length; i++)
                        {
                            expectedValues[i] = values[i + 1];
                        }
                        for (int i = 0; i < dateTable.Length; i++)
                        {
                            if (verbose)
                            {
                                Console.WriteLine("Date: <{0}>, Format: <{1}>, Expected: <{2}>", dateTable[i], format, expectedValues[i]);
                            }
                            if (!dateTable[i].ToString(format, culture).Equals(expectedValues[i]))
                            {
                                pass = false;
                                Console.WriteLine("Err_3275sg! Date: <{0}>, Format: <{1}>, Expected: <{2}>, Returned: <{3}>", dateTable[i], format, expectedValues[i], dateTable[i].ToString(format, culture));
                            }
                        }
                    }
                }
                table.Close();
            }
            fileName = baseFileName + fileCustomFormats + culture.ToString() + false.ToString();
            if (verbose)
            {
                Console.WriteLine("Processing custom Formatting, FileName - <{0}>", fileName);
            }
            temp = manager.GetString(fileName);
            if (temp == null)
            {
                throw new Exception(String.Format("Formatting table for {0} locale not found", culture.ToString()));
            }
            culture.DateTimeFormat.Calendar = gregorian;
            table     = new StringReader(temp);
            firstLine = false;
            while (true)
            {
                line = table.ReadLine();
                if (line == null)
                {
                    break;
                }
                values = line.Split(new Char[] { separator[0] });
                if (!firstLine)
                {
                    if (values[values.Length - 1] == String.Empty)
                    {
                        dateTable = new DateTime[values.Length - 2];
                    }
                    else
                    {
                        dateTable = new DateTime[values.Length - 1];
                    }
                    for (int i = 0; i < dateTable.Length; i++)
                    {
                        dateTable[i] = DateTime.ParseExact(values[i + 1], "G", culture);
                    }
                    firstLine = true;
                }
                else
                {
                    format = values[0].Trim();
                    if (values[values.Length - 1] == String.Empty)
                    {
                        expectedValues = new String[values.Length - 2];
                    }
                    else
                    {
                        expectedValues = new String[values.Length - 1];
                    }
                    for (int i = 0; i < expectedValues.Length; i++)
                    {
                        expectedValues[i] = values[i + 1];
                    }
                    for (int i = 0; i < dateTable.Length; i++)
                    {
                        if (verbose)
                        {
                            Console.WriteLine("Date: <{0}>, Format: <{1}>, Expected: <{2}>", dateTable[i], format, expectedValues[i]);
                        }
                        if (!dateTable[i].ToString(format, culture).Equals(expectedValues[i]))
                        {
                            pass = false;
                            Console.WriteLine("Err_02375sdg! DateTime: <{0}>, Format: <{1}>, Expected: <{2}>, Returned: <{3}>", dateTable[i], format, expectedValues[i], dateTable[i].ToString(format, culture));
                        }
                    }
                }
            }
            table.Close();
            fileName = baseFileName + fileCustomFormats + culture.ToString() + true.ToString();
            temp     = manager.GetString(fileName);
            if (temp != null)
            {
                if (culture.LCID == 0x040D)
                {
                    break;
                }
                if (verbose)
                {
                    Console.WriteLine("Processing formal Formatting with other otherCalendar, FileName - <{0}>", fileName);
                }
                culture.DateTimeFormat.Calendar = otherCalendar;
                table     = new StringReader(temp);
                firstLine = false;
                while (true)
                {
                    line = table.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    values = line.Split(new Char[] { separator[0] });
                    if (!firstLine)
                    {
                        if (values[values.Length - 1] == String.Empty)
                        {
                            dateTable = new DateTime[values.Length - 2];
                        }
                        else
                        {
                            dateTable = new DateTime[values.Length - 1];
                        }
                        for (int i = 0; i < dateTable.Length; i++)
                        {
                            dateTable[i] = DateTime.ParseExact(values[i + 1], "G", culture);
                        }
                        firstLine = true;
                    }
                    else
                    {
                        format = values[0].Trim();
                        if (values[values.Length - 1] == String.Empty)
                        {
                            expectedValues = new String[values.Length - 2];
                        }
                        else
                        {
                            expectedValues = new String[values.Length - 1];
                        }
                        for (int i = 0; i < expectedValues.Length; i++)
                        {
                            expectedValues[i] = values[i + 1];
                        }
                        for (int i = 0; i < dateTable.Length; i++)
                        {
                            if (verbose)
                            {
                                Console.WriteLine("Date: <{0}>, Format: <{1}>, Expected: <{2}>", dateTable[i], format, expectedValues[i]);
                            }
                            if (!dateTable[i].ToString(format, culture).Equals(expectedValues[i]))
                            {
                                pass = false;
                                Console.WriteLine("Err_3275sg! Date: <{0}>, Format: <{1}>, Expected: <{2}>, Returned: <{3}>", dateTable[i], format, expectedValues[i], dateTable[i].ToString(format, culture));
                            }
                        }
                    }
                }
                table.Close();
            }
        }
        return(pass);
    }
        public void GetMonthsInYear(int year, int era)
        {
            int expected = new GregorianCalendar().GetMonthsInYear(year, era);

            Assert.Equal(expected, new ThaiBuddhistCalendar().GetMonthsInYear(year + 543, era));
        }
    public bool runTest()
    {
        Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
        String   strLoc          = "Loc_000oo";
        String   strValue        = String.Empty;
        int      iCountErrors    = 0;
        int      iCountTestcases = 0;
        DateTime date;
        DateTime dateReturned;
        DateTime dateExpected;
        DateTime dateExpectedFromPattern;

        CultureInfo[]  cultures;
        DateTimeStyles style;
        String         s;
        Random         random;
        Hashtable      table;

        Char[] splittableChars = { ' ', '/', ':' };
        Char   ch1;

        String[] formats = { "d", "D", "f", "F", "g", "G", "m", "M", "r", "R", "s", "t", "T", "u", "U", "y", "Y" };
        Boolean  fDoneAtLeastOnce;

        String[]          dateInfoCustomFormats;
        String            parseToBeString;
        TimeZone          zone;
        TimeSpan          span;
        int               year, month, day, hour, minute, second, millisecond;
        DateTime          tempDate;
        Int32             iNumOfDates;
        Calendar          calendar = new GregorianCalendar();
        GregorianCalendar greg;

        Calendar[] calendars =
        {
            new GregorianCalendar(GregorianCalendarTypes.Arabic),
            new GregorianCalendar(GregorianCalendarTypes.Localized),
            new GregorianCalendar(GregorianCalendarTypes.MiddleEastFrench),
            new GregorianCalendar(GregorianCalendarTypes.TransliteratedEnglish),
            new GregorianCalendar(GregorianCalendarTypes.TransliteratedFrench),
            new GregorianCalendar(GregorianCalendarTypes.USEnglish),
            new HijriCalendar(),
            new TaiwanCalendar(),
            new JapaneseCalendar(),
            new KoreanCalendar(),
            new ThaiBuddhistCalendar(),
        };
        try
        {
            random = new Random();
            for (int iCalendarCount = 0; iCalendarCount < calendars.Length; iCalendarCount++)
            {
                calendar = calendars[iCalendarCount];
                strLoc   = "Loc_384sdg";
                date     = DateTime.MinValue;
                if (runAllDates)
                {
                    iNumOfDates = 80 * 365 + 90;
                    date        = GetStartDate(calendar);
                }
                else
                {
                    iNumOfDates = 100;
                }
                for (int noDates = 0; noDates < iNumOfDates; noDates++)
                {
                    strLoc = "Loc_451dsg";
                    if (runAllDates)
                    {
                        date = calendar.AddDays(date, 1);
                    }
                    else
                    {
                        year        = GetRandomYear(calendar, random);
                        month       = random.Next(1, 12);
                        day         = random.Next(1, 28);
                        hour        = random.Next(0, 23);
                        minute      = random.Next(0, 59);
                        second      = random.Next(0, 59);
                        millisecond = random.Next(0, 999);
                        date        = calendar.ToDateTime(year, month, day, hour, minute, second, millisecond);
                    }
                    strLoc = "Loc_347tsg";
                    zone   = TimeZone.CurrentTimeZone;
                    span   = zone.GetUtcOffset(date);
                    table  = new Hashtable();
                    table.Add("d", new DateTime(date.Year, date.Month, date.Day));
                    table.Add("D", new DateTime(date.Year, date.Month, date.Day));
                    table.Add("f", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0));
                    table.Add("F", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second));
                    table.Add("g", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0));
                    table.Add("G", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second));
                    table.Add("m", new DateTime(date.Year, date.Month, date.Day));
                    table.Add("M", new DateTime(date.Year, date.Month, date.Day));
                    tempDate = date.ToLocalTime();
                    table.Add("r", new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempDate.Hour, tempDate.Minute, tempDate.Second));
                    table.Add("R", new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempDate.Hour, tempDate.Minute, tempDate.Second));
                    table.Add("s", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second));
                    table.Add("t", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0));
                    table.Add("T", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second));
                    table.Add("u", new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempDate.Hour, tempDate.Minute, tempDate.Second));
                    tempDate = date.ToUniversalTime();
                    table.Add("U", new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempDate.Hour, tempDate.Minute, tempDate.Second));
                    table.Add("y", new DateTime(date.Year, date.Month, date.Day));
                    table.Add("Y", new DateTime(date.Year, date.Month, date.Day));
                    strLoc   = "Loc_3497sdg";
                    cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
                    foreach (CultureInfo culture in cultures)
                    {
                        strLoc = "Loc_37tsdg";
                        if (culture.IsNeutralCulture)
                        {
                            continue;
                        }
                        try{
                            culture.DateTimeFormat.Calendar = calendar;
                        }catch {
                            continue;
                        }
                        if ((calendar is GregorianCalendar))
                        {
                            greg = (GregorianCalendar)calendar;
                            if (greg.CalendarType == GregorianCalendarTypes.TransliteratedFrench)
                            {
                                if (calendar.GetDayOfWeek(date) == DayOfWeek.Thursday)
                                {
                                    continue;
                                }
                            }
                        }
                        if (culture.Name.Equals("div-MV"))
                        {
                            continue;
                        }
                        iCountTestcases++;
                        foreach (String format in formats)
                        {
                            if ((calendar is GregorianCalendar))
                            {
                                greg = (GregorianCalendar)calendar;
                                if (greg.CalendarType == GregorianCalendarTypes.TransliteratedFrench)
                                {
                                    if (calendar.GetDayOfWeek(date.ToUniversalTime()) == DayOfWeek.Thursday)
                                    {
                                        continue;
                                    }
                                }
                            }
                            if (!(calendar is GregorianCalendar) && (format.ToUpper().Equals("U") || format.ToUpper().Equals("R")))
                            {
                                continue;
                            }
                            if (format.ToUpper().Equals("M"))
                            {
                                if (calendar.GetDayOfMonth(date) > calendar.GetDaysInMonth(calendar.GetYear(DateTime.Now), calendar.GetMonth(date)))
                                {
                                    continue;
                                }
                            }
                            if ((culture.Name.Equals("ka-GE") ||
                                 culture.Name.Equals("af-ZA")) &&
                                format.Equals("u")
                                )
                            {
                                continue;
                            }
                            if (culture.Name.Equals("fa-IR") &&
                                format.ToUpper().Equals("Y")
                                )
                            {
                                continue;
                            }
                            if ((culture.Name.Equals("af-ZA") ||
                                 culture.Name.Equals("th-TH")) &&
                                format.ToUpper().Equals("R")
                                )
                            {
                                continue;
                            }
                            if ((culture.Name.Equals("sq-AL") ||
                                 culture.Name.Equals("mn-MN")
                                 ) &&
                                format.ToUpper().Equals("Y")
                                )
                            {
                                continue;
                            }
                            strLoc                = "Loc_386tsg";
                            s                     = date.ToString(format, culture);
                            strLoc                = "Loc_3947tsg";
                            dateExpected          = (DateTime)table[format];
                            dateInfoCustomFormats = null;
                            try
                            {
                                dateInfoCustomFormats = DateTimeFormatInfo.GetInstance(culture).GetAllDateTimePatterns(format[0]);
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Err_3498wsg");
                            }
                            try
                            {
                                strLoc       = "Loc_9374tsdg!";
                                style        = DateTimeStyles.None;
                                dateReturned = DateTime.Parse(s, culture, style);
                                if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar))
                                {
                                    iCountErrors++;
                                    Console.WriteLine("Err_93745sdg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, s, culture);
                                }
                                strLoc = "Loc_93456tfg!";
                                if (!format.Equals("U") &&
                                    (culture.Name.Equals("en-US") || culture.Name.Equals("ja-JP") || culture.Name.Equals("de-DE"))
                                    )
                                {
                                    if (culture.Name.Equals("ja-JP") && (format.Equals("r") || format.Equals("R")))
                                    {
                                        continue;
                                    }
                                    if (culture.Name.Equals("de-DE") && (format.Equals("f") || format.Equals("F") || format.Equals("G") || format.Equals("g") || format.Equals("t") || format.Equals("T")))
                                    {
                                        continue;
                                    }
                                    foreach (String patternFormat in dateInfoCustomFormats)
                                    {
                                        if (GetPatternedDate(table, patternFormat, format, out dateExpectedFromPattern))
                                        {
                                            parseToBeString = date.ToString(patternFormat, culture);
                                            dateReturned    = DateTime.Parse(parseToBeString, culture, style);
                                            if (!ResultCorrect(dateReturned, dateExpectedFromPattern, format, culture, calendar))
                                            {
                                                iCountErrors++;
                                                Console.WriteLine("Err_347tsdg! Culture: <{4}>, Format: {2}, BaseFormat: {5}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpectedFromPattern, dateReturned, patternFormat, parseToBeString, culture, format);
                                            }
                                        }
                                    }
                                }
                                strLoc       = "Loc_2837sdg!";
                                style        = DateTimeStyles.NoCurrentDateDefault;
                                dateReturned = DateTime.Parse(s, culture, style);
                                if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar))
                                {
                                    iCountErrors++;
                                    Console.WriteLine("Err_3745dsgdg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, s, culture);
                                }
                                strLoc       = "Loc_486tsg";
                                s            = s.PadLeft(random.Next(50));
                                style        = DateTimeStyles.AllowLeadingWhite;
                                dateReturned = DateTime.Parse(s, culture, style);
                                if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar))
                                {
                                    iCountErrors++;
                                    Console.WriteLine("Err_74985wgdsg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, s, culture);
                                }
                                strLoc       = "Loc_23947tsdg!";
                                s            = s.TrimStart();
                                s            = s.PadRight(random.Next(50));
                                style        = DateTimeStyles.AllowTrailingWhite;
                                dateReturned = DateTime.Parse(s, culture, style);
                                if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar))
                                {
                                    iCountErrors++;
                                    Console.WriteLine("Err_9374sdg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, GetUnicodeString(s), culture);
                                }
                                strLoc           = "Loc_234967sgd!";
                                s                = s.TrimEnd();
                                fDoneAtLeastOnce = false;
                                for (int i = 0; i < 10; i++)
                                {
                                    ch1 = splittableChars[random.Next(splittableChars.Length)];
                                    if (s.IndexOf(ch1) > 0)
                                    {
                                        s = s.Insert(s.IndexOf(ch1), new String(' ', random.Next(2, 20)));
                                        if (!fDoneAtLeastOnce)
                                        {
                                            fDoneAtLeastOnce = true;
                                        }
                                    }
                                }
                                style        = DateTimeStyles.AllowInnerWhite;
                                dateReturned = DateTime.Parse(s, culture, style);
                                if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar))
                                {
                                    iCountErrors++;
                                    Console.WriteLine("Err_43275sdg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, s, culture);
                                }
                                strLoc       = "Loc_4329076tsfg!";
                                s            = s.PadLeft(random.Next(50));
                                s            = s.PadRight(random.Next(50));
                                style        = DateTimeStyles.AllowWhiteSpaces;
                                dateReturned = DateTime.Parse(s, culture, style);
                                if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar))
                                {
                                    iCountErrors++;
                                    Console.WriteLine("Err_3497gsg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, s, culture);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (culture.Name.Equals("vi-VN") && Char.ToUpper(format[0]).Equals('Y'))
                                {
                                    ex = null;
                                }
                                else
                                {
                                    iCountErrors++;
                                    Console.WriteLine("Err_75639rge! Unexpected exception thrown {0}, Loc: {3}, format: {4}, Culture: {1}, s:<{2}>, Date: {5}", ex.GetType().Name, culture, s, strLoc, format, date);
                                }
                            }
                        }
                    }
                }
            }
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general.ToString());
        }
        if (iCountErrors == 0)
        {
            Console.WriteLine("paSs. " + s_strTFName + " ,iCountTestcases==" + iCountTestcases.ToString());
            return(true);
        }
        else
        {
            Console.WriteLine("FAiL! " + s_strTFName + " ,inCountErrors==" + iCountErrors.ToString() + " , BugNums?: " + s_strActiveBugNums);
            return(false);
        }
    }
 public bool runTest()
   {
   Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   int iCountErrors = 0;
   int iCountTestcases = 0;
   try
     {
     DateTime dTest;
     HebrewCalendar hCal = new HebrewCalendar();
     JulianCalendar jCal = new JulianCalendar();
     HijriCalendar hiCal = new HijriCalendar ();
     GregorianCalendar gCal = new GregorianCalendar ();
     JapaneseCalendar jaCal = new JapaneseCalendar ();
     KoreanCalendar kCal = new KoreanCalendar ();
     ThaiBuddhistCalendar tCal = new ThaiBuddhistCalendar ();
     strLoc = "Loc_100vy";
     iCountTestcases++;
     dTest = new DateTime(5360,04,14,hCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_100aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_100bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_100cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_100dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_100ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_100ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_100gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_101vy";
     iCountTestcases++;
     dTest = new DateTime(1599,12,22,jCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_101aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_101bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_101cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_101dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_101ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_101ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_101gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_102vy";
     iCountTestcases++;
     dTest = new DateTime(1008,06,15,hiCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_102aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_102bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_102cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_102dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_102ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_102ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_102gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_103vy";
     iCountTestcases++;
     dTest = new DateTime(1600,1,1,gCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_103aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_103bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_103cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_103dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_103ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_103ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_103gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_104vy";
     iCountTestcases++;
     dTest = new DateTime(1,1,8,jaCal); 	
     if (dTest.Year != 1989)
       {
       ++iCountErrors;	
       printerr( "Error_104aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_104bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 8)
       {
       ++iCountErrors;	
       printerr( "Error_104cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_104dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_104ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_104ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_104gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_105vy";
     iCountTestcases++;
     dTest = new DateTime(3933,1,1,kCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_105aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_105bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_105cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_105dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_105ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_105ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_105gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_106vy";
     iCountTestcases++;
     dTest = new DateTime(2143,1,1,tCal); 	
     if (dTest.Year != 1600)
       {
       ++iCountErrors;	
       printerr( "Error_106aa! DateTime object was not set correctly");
       }
     if (dTest.Month != 1)
       {
       ++iCountErrors;	
       printerr( "Error_106bb! DateTime object was not set correctly");
       }
     if (dTest.Day != 1)
       {
       ++iCountErrors;	
       printerr( "Error_106cc! DateTime object was not set correctly");
       }
     if (dTest.Hour != 0)
       {
       ++iCountErrors;	
       printerr( "Error_106dd! DateTime object was not set correctly");
       }
     if (dTest.Minute != 0)
       {
       ++iCountErrors;	
       printerr( "Error_106ee! DateTime object was not set correctly");
       }
     if (dTest.Second != 0)
       {
       ++iCountErrors;	
       printerr( "Error_106ff! DateTime object was not set correctly");
       }
     if (dTest.Millisecond != 0)
       {
       ++iCountErrors;	
       printerr( "Error_106gg! DateTime object was not set correctly");
       }
     strLoc = "Loc_524vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(0,03,25,hCal);
       iCountErrors++;
       printerr( "Error_200bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_512ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_200aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_333vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(10000,03,25,hCal);
       iCountErrors++;
       printerr( "Error_300bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_333ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_300aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_444vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(5000,0,25,hCal);
       iCountErrors++;
       printerr( "Error_400bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_444ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_400aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_555vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(5000,13,25,jCal);
       iCountErrors++;
       printerr( "Error_500bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_555ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_500aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_665vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(2000,03,0,jCal);
       iCountErrors++;
       printerr( "Error_600bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_665ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_600aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_777vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(2000,03,32,jCal);
       iCountErrors++;
       printerr( "Error_700bb! No exception thrown");
       }
     catch (ArgumentOutOfRangeException argexc)
       {
       printinfo( "Info_775ad! Caught ArguementOutOfRangeException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_700aa! Wrong exception thrown: " + e.ToString());
       }
     strLoc = "Loc_888vy";
     iCountTestcases++;
     try
       {
       dTest = new DateTime(2000,03,14,null);
       iCountErrors++;
       printerr( "Error_800bb! No exception thrown");
       }
     catch (ArgumentNullException argexc)
       {
       printinfo( "Info_885ad! Caught ArguementNullException");
       }
     catch (Exception e)
       {
       ++iCountErrors;	
       printerr( "Error_800aa! Wrong exception thrown: " + e.ToString());
       }
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 )
     {
     Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
     return true;
     }
   else
     {
     Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
Beispiel #35
0
        public void TestWriteWellKnown1()
        {
            POIDataSamples _samples = POIDataSamples.GetHPSFInstance();
            FileStream     doc1     = _samples.GetFile(POI_FS);

            /* Read a Test document <em>doc1</em> into a POI filesystem. */
            POIFSFileSystem poifs    = new POIFSFileSystem(doc1);
            DirectoryEntry  dir      = poifs.Root;
            DocumentEntry   siEntry  = (DocumentEntry)dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME);
            DocumentEntry   dsiEntry = (DocumentEntry)dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);

            /*
             * Read the summary information stream and the document summary
             * information stream from the POI filesystem.
             *
             * Please note that the result consists of SummaryInformation and
             * DocumentSummaryInformation instances which are in memory only. To
             * make them permanent they have to be written to a POI filesystem
             * explicitly (overwriting the former contents). Then the POI filesystem
             * should be saved to a file.
             */
            POIFSDocumentReader dis = new POIFSDocumentReader(siEntry);
            PropertySet         ps  = new PropertySet(dis);
            SummaryInformation  si  = new SummaryInformation(ps);

            dis = new POIFSDocumentReader(dsiEntry);
            ps  = new PropertySet(dis);
            DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps);

            /*
             * Write all properties supported by HPSF to the summary information
             * (e.g. author, edit date, application name) and to the document
             * summary information (e.g. company, manager).
             */
            Calendar cal = new GregorianCalendar();
            //long time1 = (long)cal.GetMilliseconds(new DateTime(2000, 6, 6, 6, 6, 6));

            //long time2 = (long)cal.GetMilliseconds(new DateTime(2001, 7, 7, 7, 7, 7));
            //long time3 = (long)cal.GetMilliseconds(new DateTime(2002, 8, 8, 8, 8, 8));

            int      nr = 4711;
            String   P_APPLICATION_NAME    = "Microsoft Office Word";
            String   P_AUTHOR              = "Rainer Klute";
            int      P_CHAR_COUNT          = 125;
            String   P_COMMENTS            = ""; //"Comments";
            DateTime P_CREATE_DATE_TIME    = new DateTime(2006, 2, 1, 7, 36, 0);
            long     P_EDIT_TIME           = ++nr * 1000 * 10;
            String   P_KEYWORDS            = "Test HPSF SummaryInformation DocumentSummaryInformation Writing";
            String   P_LAST_AUTHOR         = "LastAuthor";
            DateTime?P_LAST_PRINTED        = null;
            DateTime P_LAST_SAVE_DATE_TIME = new DateTime(2008, 9, 30, 9, 54, 0);
            int      P_PAGE_COUNT          = 1;
            String   P_REV_NUMBER          = "RevNumber";
            int      P_SECURITY            = 1;
            String   P_SUBJECT             = "Subject";
            String   P_TEMPLATE            = "Normal.dotm";
            // FIXME (byte array properties not yet implemented): byte[] P_THUMBNAIL = new byte[123];
            String P_TITLE      = "This document is used for testing POI HPSF¡¯s writing capabilities for the summary information stream and the document summary information stream";
            int    P_WORD_COUNT = 21;

            int    P_BYTE_COUNT = ++nr;
            String P_CATEGORY   = "Category";
            String P_COMPANY    = "Rainer Klute IT-Consulting GmbH";
            // FIXME (byte array properties not yet implemented): byte[]  P_DOCPARTS = new byte[123];
            // FIXME (byte array properties not yet implemented): byte[]  P_HEADING_PAIR = new byte[123];
            int      P_HIDDEN_COUNT        = ++nr;
            int      P_LINE_COUNT          = ++nr;
            bool     P_LINKS_DIRTY         = true;
            String   P_MANAGER             = "Manager";
            int      P_MM_CLIP_COUNT       = ++nr;
            int      P_NOTE_COUNT          = ++nr;
            int      P_PAR_COUNT           = ++nr;
            String   P_PRESENTATION_FORMAT = "PresentationFormat";
            bool     P_SCALE       = false;
            int      P_SLIDE_COUNT = ++nr;
            DateTime now           = DateTime.Now;

            int    POSITIVE_INTEGER = 2222;
            long   POSITIVE_LONG    = 3333;
            Double POSITIVE_DOUBLE  = 4444;
            int    NEGATIVE_INTEGER = 2222;
            long   NEGATIVE_LONG    = 3333;
            Double NEGATIVE_DOUBLE  = 4444;

            int    MAX_INTEGER = int.MaxValue;
            int    MIN_INTEGER = int.MinValue;
            long   MAX_LONG    = long.MaxValue;
            long   MIN_LONG    = long.MinValue;
            Double MAX_DOUBLE  = Double.MaxValue;
            Double MIN_DOUBLE  = Double.MinValue;

            si.ApplicationName  = P_APPLICATION_NAME;
            si.Author           = P_AUTHOR;
            si.CharCount        = P_CHAR_COUNT;
            si.Comments         = P_COMMENTS;
            si.CreateDateTime   = P_CREATE_DATE_TIME;
            si.EditTime         = P_EDIT_TIME;
            si.Keywords         = P_KEYWORDS;
            si.LastAuthor       = P_LAST_AUTHOR;
            si.LastPrinted      = P_LAST_PRINTED;
            si.LastSaveDateTime = P_LAST_SAVE_DATE_TIME;
            si.PageCount        = P_PAGE_COUNT;
            si.RevNumber        = P_REV_NUMBER;
            si.Security         = P_SECURITY;
            si.Subject          = P_SUBJECT;
            si.Template         = P_TEMPLATE;
            // FIXME (byte array properties not yet implemented): si.Thumbnail=P_THUMBNAIL;
            si.Title     = P_TITLE;
            si.WordCount = P_WORD_COUNT;

            dsi.ByteCount = P_BYTE_COUNT;
            dsi.Category  = P_CATEGORY;
            dsi.Company   = P_COMPANY;
            // FIXME (byte array properties not yet implemented): dsi.Docparts=P_DOCPARTS;
            // FIXME (byte array properties not yet implemented): dsi.HeadingPair=P_HEADING_PAIR;
            dsi.HiddenCount        = P_HIDDEN_COUNT;
            dsi.LineCount          = P_LINE_COUNT;
            dsi.LinksDirty         = P_LINKS_DIRTY;
            dsi.Manager            = P_MANAGER;
            dsi.MMClipCount        = P_MM_CLIP_COUNT;
            dsi.NoteCount          = P_NOTE_COUNT;
            dsi.ParCount           = P_PAR_COUNT;
            dsi.PresentationFormat = P_PRESENTATION_FORMAT;
            dsi.Scale      = P_SCALE;
            dsi.SlideCount = P_SLIDE_COUNT;

            CustomProperties customProperties = dsi.CustomProperties;

            if (customProperties == null)
            {
                customProperties = new CustomProperties();
            }
            customProperties.Put("Schlüssel 1", "Wert 1");
            customProperties.Put("Schlüssel 2", "Wert 2");
            customProperties.Put("Schlüssel 3", "Wert 3");
            customProperties.Put("Schlüssel 4", "Wert 4");
            customProperties.Put("positive_int", POSITIVE_INTEGER);
            customProperties.Put("positive_long", POSITIVE_LONG);
            customProperties.Put("positive_Double", POSITIVE_DOUBLE);
            customProperties.Put("negative_int", NEGATIVE_INTEGER);
            customProperties.Put("negative_long", NEGATIVE_LONG);
            customProperties.Put("negative_Double", NEGATIVE_DOUBLE);
            customProperties.Put("Boolean", true);
            customProperties.Put("Date", now);
            customProperties.Put("max_int", MAX_INTEGER);
            customProperties.Put("min_int", MIN_INTEGER);
            customProperties.Put("max_long", MAX_LONG);
            customProperties.Put("min_long", MIN_LONG);
            customProperties.Put("max_Double", MAX_DOUBLE);
            customProperties.Put("min_Double", MIN_DOUBLE);
            dsi.CustomProperties = customProperties;

            /* Write the summary information stream and the document summary
             * information stream to the POI filesystem. */
            si.Write(dir, siEntry.Name);
            dsi.Write(dir, dsiEntry.Name);

            /* Write the POI filesystem to a (temporary) file <em>doc2</em>
             * and Close the latter. */
            FileStream doc2 = File.Create(testContextInstance.TestDir + @"\POI_HPSF_Test2.tmp");

            poifs.WriteFileSystem(doc2);
            //doc2.Flush();

            /*
             * Open <em>doc2</em> for Reading and check summary information and
             * document summary information. All properties written before must be
             * found in the property streams of <em>doc2</em> and have the correct
             * values.
             */
            doc2.Flush();
            doc2.Position = 0;
            POIFSFileSystem poifs2 = new POIFSFileSystem(doc2);

            dir      = poifs2.Root;
            siEntry  = (DocumentEntry)dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME);
            dsiEntry = (DocumentEntry)dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);

            dis = new POIFSDocumentReader(siEntry);
            ps  = new PropertySet(dis);
            si  = new SummaryInformation(ps);
            dis = new POIFSDocumentReader(dsiEntry);
            ps  = new PropertySet(dis);
            dsi = new DocumentSummaryInformation(ps);

            Assert.AreEqual(P_APPLICATION_NAME, si.ApplicationName);
            Assert.AreEqual(P_AUTHOR, si.Author);
            Assert.AreEqual(P_CHAR_COUNT, si.CharCount);
            Assert.AreEqual(P_COMMENTS, si.Comments);
            Assert.AreEqual(P_CREATE_DATE_TIME, si.CreateDateTime);
            Assert.AreEqual(P_EDIT_TIME, si.EditTime);
            Assert.AreEqual(P_KEYWORDS, si.Keywords);
            Assert.AreEqual(P_LAST_AUTHOR, si.LastAuthor);
            Assert.AreEqual(P_LAST_PRINTED, si.LastPrinted);
            Assert.AreEqual(P_LAST_SAVE_DATE_TIME, si.LastSaveDateTime);
            Assert.AreEqual(P_PAGE_COUNT, si.PageCount);
            Assert.AreEqual(P_REV_NUMBER, si.RevNumber);
            Assert.AreEqual(P_SECURITY, si.Security);
            Assert.AreEqual(P_SUBJECT, si.Subject);
            Assert.AreEqual(P_TEMPLATE, si.Template);
            // FIXME (byte array properties not yet implemented): Assert.AreEqual(P_THUMBNAIL, si.Thumbnail);
            Assert.AreEqual(P_TITLE, si.Title);
            Assert.AreEqual(P_WORD_COUNT, si.WordCount);

            Assert.AreEqual(P_BYTE_COUNT, dsi.ByteCount);
            Assert.AreEqual(P_CATEGORY, dsi.Category);
            Assert.AreEqual(P_COMPANY, dsi.Company);
            // FIXME (byte array properties not yet implemented): Assert.AreEqual(P_, dsi.Docparts);
            // FIXME (byte array properties not yet implemented): Assert.AreEqual(P_, dsi.HeadingPair);
            Assert.AreEqual(P_HIDDEN_COUNT, dsi.HiddenCount);
            Assert.AreEqual(P_LINE_COUNT, dsi.LineCount);
            Assert.AreEqual(P_LINKS_DIRTY, dsi.LinksDirty);
            Assert.AreEqual(P_MANAGER, dsi.Manager);
            Assert.AreEqual(P_MM_CLIP_COUNT, dsi.MMClipCount);
            Assert.AreEqual(P_NOTE_COUNT, dsi.NoteCount);
            Assert.AreEqual(P_PAR_COUNT, dsi.ParCount);
            Assert.AreEqual(P_PRESENTATION_FORMAT, dsi.PresentationFormat);
            Assert.AreEqual(P_SCALE, dsi.Scale);
            Assert.AreEqual(P_SLIDE_COUNT, dsi.SlideCount);

            CustomProperties cps = dsi.CustomProperties;

            //Assert.AreEqual(customProperties, cps);
            Assert.IsNull(cps["No value available"]);
            Assert.AreEqual("Wert 1", cps["Schlüssel 1"]);
            Assert.AreEqual("Wert 2", cps["Schlüssel 2"]);
            Assert.AreEqual("Wert 3", cps["Schlüssel 3"]);
            Assert.AreEqual("Wert 4", cps["Schlüssel 4"]);
            Assert.AreEqual(POSITIVE_INTEGER, cps["positive_int"]);
            Assert.AreEqual(POSITIVE_LONG, cps["positive_long"]);
            Assert.AreEqual(POSITIVE_DOUBLE, cps["positive_Double"]);
            Assert.AreEqual(NEGATIVE_INTEGER, cps["negative_int"]);
            Assert.AreEqual(NEGATIVE_LONG, cps["negative_long"]);
            Assert.AreEqual(NEGATIVE_DOUBLE, cps["negative_Double"]);
            Assert.AreEqual(true, cps["Boolean"]);
            Assert.AreEqual(now, cps["Date"]);
            Assert.AreEqual(MAX_INTEGER, cps["max_int"]);
            Assert.AreEqual(MIN_INTEGER, cps["min_int"]);
            Assert.AreEqual(MAX_LONG, cps["max_long"]);
            Assert.AreEqual(MIN_LONG, cps["min_long"]);
            Assert.AreEqual(MAX_DOUBLE, cps["max_Double"]);
            Assert.AreEqual(MIN_DOUBLE, cps["min_Double"]);

            /* Remove all properties supported by HPSF from the summary
             * information (e.g. author, edit date, application name) and from the
             * document summary information (e.g. company, manager). */
            si.RemoveApplicationName();
            si.RemoveAuthor();
            si.RemoveCharCount();
            si.RemoveComments();
            si.RemoveCreateDateTime();
            si.RemoveEditTime();
            si.RemoveKeywords();
            si.RemoveLastAuthor();
            si.RemoveLastPrinted();
            si.RemoveLastSaveDateTime();
            si.RemovePageCount();
            si.RemoveRevNumber();
            si.RemoveSecurity();
            si.RemoveSubject();
            si.RemoveTemplate();
            si.RemoveThumbnail();
            si.RemoveTitle();
            si.RemoveWordCount();

            dsi.RemoveByteCount();
            dsi.RemoveCategory();
            dsi.RemoveCompany();
            dsi.RemoveCustomProperties();
            dsi.RemoveDocparts();
            dsi.RemoveHeadingPair();
            dsi.RemoveHiddenCount();
            dsi.RemoveLineCount();
            dsi.RemoveLinksDirty();
            dsi.RemoveManager();
            dsi.RemoveMMClipCount();
            dsi.RemoveNoteCount();
            dsi.RemoveParCount();
            dsi.RemovePresentationFormat();
            dsi.RemoveScale();
            dsi.RemoveSlideCount();

            /*
             * <li>Write the summary information stream and the document summary
             * information stream to the POI filesystem. */
            si.Write(dir, siEntry.Name);
            dsi.Write(dir, dsiEntry.Name);

            /*
             * <li>Write the POI filesystem to a (temporary) file <em>doc3</em>
             * and Close the latter. */
            FileStream doc3 = File.Create(testContextInstance.TestDir + @"\POI_HPSF_Test3.tmp");

            poifs2.WriteFileSystem(doc3);
            doc3.Position = 0;

            /*
             * Open <em>doc3</em> for Reading and check summary information
             * and document summary information. All properties Removed before must not
             * be found in the property streams of <em>doc3</em>.
             */
            POIFSFileSystem poifs3 = new POIFSFileSystem(doc3);


            dir      = poifs3.Root;
            siEntry  = (DocumentEntry)dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME);
            dsiEntry = (DocumentEntry)dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);

            dis = new POIFSDocumentReader(siEntry);
            ps  = new PropertySet(dis);
            si  = new SummaryInformation(ps);
            dis = new POIFSDocumentReader(dsiEntry);
            ps  = new PropertySet(dis);
            dsi = new DocumentSummaryInformation(ps);

            Assert.AreEqual(null, si.ApplicationName);
            Assert.AreEqual(null, si.Author);
            Assert.AreEqual(0, si.CharCount);
            Assert.IsTrue(si.WasNull);
            Assert.AreEqual(null, si.Comments);
            Assert.AreEqual(null, si.CreateDateTime);
            Assert.AreEqual(0, si.EditTime);
            Assert.IsTrue(si.WasNull);
            Assert.AreEqual(null, si.Keywords);
            Assert.AreEqual(null, si.LastAuthor);
            Assert.AreEqual(null, si.LastPrinted);
            Assert.AreEqual(null, si.LastSaveDateTime);
            Assert.AreEqual(0, si.PageCount);
            Assert.IsTrue(si.WasNull);
            Assert.AreEqual(null, si.RevNumber);
            Assert.AreEqual(0, si.Security);
            Assert.IsTrue(si.WasNull);
            Assert.AreEqual(null, si.Subject);
            Assert.AreEqual(null, si.Template);
            Assert.AreEqual(null, si.Thumbnail);
            Assert.AreEqual(null, si.Title);
            Assert.AreEqual(0, si.WordCount);
            Assert.IsTrue(si.WasNull);

            Assert.AreEqual(0, dsi.ByteCount);
            Assert.IsTrue(dsi.WasNull);
            Assert.AreEqual(null, dsi.Category);
            Assert.AreEqual(null, dsi.CustomProperties);
            // FIXME (byte array properties not yet implemented): Assert.AreEqual(null, dsi.Docparts);
            // FIXME (byte array properties not yet implemented): Assert.AreEqual(null, dsi.HeadingPair);
            Assert.AreEqual(0, dsi.HiddenCount);
            Assert.IsTrue(dsi.WasNull);
            Assert.AreEqual(0, dsi.LineCount);
            Assert.IsTrue(dsi.WasNull);
            Assert.AreEqual(false, dsi.LinksDirty);
            Assert.IsTrue(dsi.WasNull);
            Assert.AreEqual(null, dsi.Manager);
            Assert.AreEqual(0, dsi.MMClipCount);
            Assert.IsTrue(dsi.WasNull);
            Assert.AreEqual(0, dsi.NoteCount);
            Assert.IsTrue(dsi.WasNull);
            Assert.AreEqual(0, dsi.ParCount);
            Assert.IsTrue(dsi.WasNull);
            Assert.AreEqual(null, dsi.PresentationFormat);
            Assert.AreEqual(false, dsi.Scale);
            Assert.IsTrue(dsi.WasNull);
            Assert.AreEqual(0, dsi.SlideCount);
            Assert.IsTrue(dsi.WasNull);

            File.Delete(testContextInstance.TestDir + @"\POI_HPSF_Test3.tmp");
            File.Delete(testContextInstance.TestDir + @"\POI_HPSF_Test2.tmp");
        }
        /*
         * Gives event correct date based on year
         */
        public static void resetEvent(Event newEvent)
        {
            int       year, day;
            int       sundayCount, mondayCount;
            MoonPhase moonPhase = new MoonPhase();

            switch (newEvent.getName())
            {
            case "Chinese New Year":
                year = DateTime.Now.Year;

                while (true)
                {
                    ChineseLunisolarCalendar chinese   = new ChineseLunisolarCalendar();
                    GregorianCalendar        gregorian = new GregorianCalendar();
                    DateTime chineseNewYear            = chinese.ToDateTime(year, 1, 1, 0, 0, 0, 0);
                    DateTime cny = new DateTime(gregorian.GetYear(chineseNewYear), gregorian.GetMonth(chineseNewYear), gregorian.GetDayOfMonth(chineseNewYear));
                    if (cny > DateTime.Now)
                    {
                        newEvent.setDate(new DateTime(cny.Year, cny.Month, cny.Day));
                        break;
                    }
                    else
                    {
                        year++;
                    }
                }
                break;

            case "Columbus Day":
                year        = DateTime.Now.Year;
                day         = 1;
                mondayCount = 0;
                while (true)
                {
                    if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Monday)
                    {
                        mondayCount++;
                        if (mondayCount == 2)
                        {
                            break;
                        }
                    }
                    day++;
                }
                if (DateTime.Now.Month == newEvent.getDate().Month&& DateTime.Now.Day > day || DateTime.Now.Month > newEvent.getDate().Month)
                {
                    year        = DateTime.Now.Year + 1;
                    day         = 1;
                    mondayCount = 0;
                    while (true)
                    {
                        if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Monday)
                        {
                            mondayCount++;
                            if (mondayCount == 2)
                            {
                                break;
                            }
                        }
                        day++;
                    }
                    newEvent.setDate(new DateTime(DateTime.Now.Year + 1, newEvent.getDate().Month, day, 0, 0, 0));
                }
                else
                {
                    newEvent.setDate(new DateTime(DateTime.Now.Year, newEvent.getDate().Month, day, 0, 0, 0));
                }
                break;

            case "Daylight Saving Time Ends":
                year = DateTime.Now.Year;
                day  = 1;
                while (true)
                {
                    if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Sunday)
                    {
                        break;
                    }
                    day++;
                }
                if (DateTime.Now.Month == newEvent.getDate().Month&& DateTime.Now.Day > day || DateTime.Now.Month > newEvent.getDate().Month)
                {
                    year = DateTime.Now.Year + 1;
                    day  = 1;
                    while (true)
                    {
                        if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Sunday)
                        {
                            break;
                        }
                        day++;
                    }
                    newEvent.setDate(new DateTime(year, newEvent.getDate().Month, day, newEvent.getDate().Hour, 0, 0));
                }
                else
                {
                    newEvent.setDate(new DateTime(year, newEvent.getDate().Month, day, newEvent.getDate().Hour, 0, 0));
                }
                break;

            case "Daylight Saving Time Starts":
                year        = DateTime.Now.Year;
                day         = 1;
                sundayCount = 0;
                while (true)
                {
                    if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Sunday)
                    {
                        sundayCount++;
                        if (sundayCount == 2)
                        {
                            break;
                        }
                    }
                    day++;
                }
                if (DateTime.Now.Month == newEvent.getDate().Month&& DateTime.Now.Day > day || DateTime.Now.Month > newEvent.getDate().Month)
                {
                    year        = DateTime.Now.Year + 1;
                    day         = 1;
                    sundayCount = 0;
                    while (true)
                    {
                        if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Sunday)
                        {
                            sundayCount++;
                            if (sundayCount == 2)
                            {
                                break;
                            }
                        }
                        day++;
                    }
                    newEvent.setDate(new DateTime(year, newEvent.getDate().Month, day, newEvent.getDate().Hour, 0, 0));
                }
                else
                {
                    newEvent.setDate(new DateTime(year, newEvent.getDate().Month, day, newEvent.getDate().Hour, 0, 0));
                }
                break;

            case "Easter":
                year = DateTime.Now.Year;

                while (true)
                {
                    int a = year % 19;
                    int b = year / 100;
                    int c = year % 100;
                    int d = b / 4;
                    int e = b % 4;
                    int f = (b + 8) / 25;
                    int g = (b - f + 1) / 3;
                    int h = (19 * a + b - d - g + 15) % 30;
                    int i = c / 4;
                    int k = c % 4;
                    int l = (32 + 2 * e + 2 * i - h - k) % 7;
                    int m = (a + 11 * h + 22 * l) / 451;
                    int n = (h + l - 7 * m + 114) / 31;
                    int p = (h + l - 7 * m + 114) % 31;

                    DateTime easter = new DateTime(year, n, p + 1);
                    if (easter > DateTime.Now)
                    {
                        newEvent.setDate(new DateTime(easter.Year, easter.Month, easter.Day, 0, 0, 0));
                        break;
                    }
                    else
                    {
                        year++;
                    }
                }
                break;

            case "Father's Day":
                year        = DateTime.Now.Year;
                day         = 1;
                sundayCount = 0;
                while (true)
                {
                    if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Sunday)
                    {
                        sundayCount++;
                        if (sundayCount == 3)
                        {
                            break;
                        }
                    }
                    day++;
                }
                if (DateTime.Now.Month == newEvent.getDate().Month&& DateTime.Now.Day > day || DateTime.Now.Month > newEvent.getDate().Month)
                {
                    year        = DateTime.Now.Year + 1;
                    day         = 1;
                    sundayCount = 0;
                    while (true)
                    {
                        if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Sunday)
                        {
                            sundayCount++;
                            if (sundayCount == 3)
                            {
                                break;
                            }
                        }
                        day++;
                    }
                    newEvent.setDate(new DateTime(DateTime.Now.Year + 1, newEvent.getDate().Month, day, 0, 0, 0));
                }
                else
                {
                    newEvent.setDate(new DateTime(DateTime.Now.Year, newEvent.getDate().Month, day, 0, 0, 0));
                }
                break;

            case "Friday the 13th":
                DateTime temp = DateTime.Now;

                while (temp.DayOfWeek != DayOfWeek.Friday)
                {
                    temp = temp.AddDays(1);
                }

                while (temp.Day != 13)
                {
                    temp = temp.AddDays(7);
                }

                temp = new DateTime(temp.Year, temp.Month, temp.Day, 0, 0, 0);

                newEvent.setDate(temp);
                break;

            case "Full Moon":
                newEvent.setDate(moonPhase.GetNextFullMoon(DateTime.Today));
                break;

            case "Labor Day":
                year = DateTime.Now.Year;
                day  = 1;
                while (true)
                {
                    if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Monday)
                    {
                        break;
                    }
                    day++;
                }
                if (DateTime.Now.Month == newEvent.getDate().Month&& DateTime.Now.Day > day || DateTime.Now.Month > newEvent.getDate().Month)
                {
                    year = DateTime.Now.Year + 1;
                    day  = 1;
                    while (true)
                    {
                        if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Monday)
                        {
                            break;
                        }
                        day++;
                    }
                    newEvent.setDate(new DateTime(DateTime.Now.Year + 1, newEvent.getDate().Month, day, 0, 0, 0));
                }
                else
                {
                    newEvent.setDate(new DateTime(DateTime.Now.Year, newEvent.getDate().Month, day, 0, 0, 0));
                }
                break;

            case "Leap Day":
                year = DateTime.Now.Year;
                if (DateTime.Now.Month > 2)
                {
                    year++;
                }
                while (true)
                {
                    if (year % 4 != 0)
                    {
                        year++;
                        continue;
                    }
                    else if (year % 100 != 0)
                    {
                        break;
                    }
                    else if (year % 400 != 0)
                    {
                        year++;
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                newEvent.setDate(new DateTime(year, newEvent.getDate().Month, 29, newEvent.getDate().Hour, 0, 0));
                break;

            case "Mardi Gras":
                year = DateTime.Now.Year;

                while (true)
                {
                    int a = year % 19;
                    int b = year / 100;
                    int c = year % 100;
                    int d = b / 4;
                    int e = b % 4;
                    int f = (b + 8) / 25;
                    int g = (b - f + 1) / 3;
                    int h = (19 * a + b - d - g + 15) % 30;
                    int i = c / 4;
                    int k = c % 4;
                    int l = (32 + 2 * e + 2 * i - h - k) % 7;
                    int m = (a + 11 * h + 22 * l) / 451;
                    int n = (h + l - 7 * m + 114) / 31;
                    int p = (h + l - 7 * m + 114) % 31;

                    DateTime easter = new DateTime(year, n, p + 1);
                    if (easter.AddDays(-47) > DateTime.Now)
                    {
                        newEvent.setDate((new DateTime(easter.Year, easter.Month, easter.Day, 0, 0, 0)).AddDays(-47));
                        break;
                    }
                    else
                    {
                        year++;
                    }
                }
                break;

            case "Martin Luther King Jr. Day":
                year        = DateTime.Now.Year;
                day         = 1;
                mondayCount = 0;
                while (true)
                {
                    if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Monday)
                    {
                        mondayCount++;
                        if (mondayCount == 3)
                        {
                            break;
                        }
                    }
                    day++;
                }
                if (DateTime.Now.Month == newEvent.getDate().Month&& DateTime.Now.Day > day || DateTime.Now.Month > newEvent.getDate().Month)
                {
                    year        = DateTime.Now.Year + 1;
                    day         = 1;
                    mondayCount = 0;
                    while (true)
                    {
                        if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Monday)
                        {
                            mondayCount++;
                            if (mondayCount == 3)
                            {
                                break;
                            }
                        }
                        day++;
                    }
                    newEvent.setDate(new DateTime(DateTime.Now.Year + 1, newEvent.getDate().Month, day, 0, 0, 0));
                }
                else
                {
                    newEvent.setDate(new DateTime(DateTime.Now.Year, newEvent.getDate().Month, day, 0, 0, 0));
                }
                break;

            case "Memorial Day":
                year = DateTime.Now.Year;
                day  = 31;
                while (true)
                {
                    if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Monday)
                    {
                        break;
                    }
                    day--;
                }
                if (DateTime.Now.Month == newEvent.getDate().Month&& DateTime.Now.Day > day || DateTime.Now.Month > newEvent.getDate().Month)
                {
                    year = DateTime.Now.Year + 1;
                    day  = 31;
                    while (true)
                    {
                        if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Monday)
                        {
                            break;
                        }
                        day--;
                    }
                    newEvent.setDate(new DateTime(DateTime.Now.Year + 1, newEvent.getDate().Month, day, 0, 0, 0));
                }
                else
                {
                    newEvent.setDate(new DateTime(DateTime.Now.Year, newEvent.getDate().Month, day, 0, 0, 0));
                }
                break;

            case "Mother's Day":
                year        = DateTime.Now.Year;
                day         = 1;
                sundayCount = 0;
                while (true)
                {
                    if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Sunday)
                    {
                        sundayCount++;
                        if (sundayCount == 2)
                        {
                            break;
                        }
                    }
                    day++;
                }
                if (DateTime.Now.Month == newEvent.getDate().Month&& DateTime.Now.Day > day || DateTime.Now.Month > newEvent.getDate().Month)
                {
                    year        = DateTime.Now.Year + 1;
                    day         = 1;
                    sundayCount = 0;
                    while (true)
                    {
                        if (new DateTime(year, newEvent.getDate().Month, day).DayOfWeek == DayOfWeek.Sunday)
                        {
                            sundayCount++;
                            if (sundayCount == 2)
                            {
                                break;
                            }
                        }
                        day++;
                    }
                    newEvent.setDate(new DateTime(DateTime.Now.Year + 1, newEvent.getDate().Month, day, 0, 0, 0));
                }
                else
                {
                    newEvent.setDate(new DateTime(DateTime.Now.Year, newEvent.getDate().Month, day, 0, 0, 0));
                }
                break;

            case "New Moon":
                newEvent.setDate(moonPhase.GetNextNewMoon(DateTime.Today));
                break;

            case "Thanksgiving":
                year = DateTime.Now.Year;
                day  = 1;
                int thursdayCount = 0;
                while (true)
                {
                    if (new DateTime(year, 11, day).DayOfWeek == DayOfWeek.Thursday)
                    {
                        thursdayCount++;
                        if (thursdayCount == 4)
                        {
                            break;
                        }
                    }
                    day++;
                }
                if (DateTime.Now.Month == 11 && DateTime.Now.Day > day || DateTime.Now.Month > 11)
                {
                    year          = DateTime.Now.Year + 1;
                    day           = 1;
                    thursdayCount = 0;
                    while (true)
                    {
                        if (new DateTime(year, 11, day).DayOfWeek == DayOfWeek.Thursday)
                        {
                            thursdayCount++;
                            if (thursdayCount == 4)
                            {
                                break;
                            }
                        }
                        day++;
                    }
                    newEvent.setDate(new DateTime(DateTime.Now.Year + 1, newEvent.getDate().Month, day, 0, 0, 0));
                }
                else
                {
                    newEvent.setDate(new DateTime(DateTime.Now.Year, newEvent.getDate().Month, day, 0, 0, 0));
                }
                break;

            default:
                //special case for user event on Feb 29
                if (newEvent.getDate().Day == 29 && newEvent.getDate().Month == 2 || newEvent.isOneTimeEvent())
                {
                    newEvent.setDate(new DateTime(newEvent.getDate().Year, newEvent.getDate().Month, newEvent.getDate().Day, newEvent.getDate().Hour, newEvent.getDate().Minute, newEvent.getDate().Second));
                }
                else if (DateTime.Now.Month == newEvent.getDate().Month&& DateTime.Now.Day > newEvent.getDate().Day || DateTime.Now.Month > newEvent.getDate().Month)
                {
                    newEvent.setDate(new DateTime(DateTime.Now.Year + 1, newEvent.getDate().Month, newEvent.getDate().Day, newEvent.getDate().Hour, newEvent.getDate().Minute, newEvent.getDate().Second));
                }
                else
                {
                    newEvent.setDate(new DateTime(DateTime.Now.Year, newEvent.getDate().Month, newEvent.getDate().Day, newEvent.getDate().Hour, newEvent.getDate().Minute, newEvent.getDate().Second));
                }
                break;
            }
        }
        /// <summary>
        /// 获得 当前周数
        /// </summary>
        protected int GetWeekCount()
        {
            var gc = new GregorianCalendar();

            return(gc.GetWeekOfYear(Value, CalendarWeekRule.FirstDay, DayOfWeek.Sunday));
        }
 public void IsLeapDay(int year, int month, int day, int era)
 {
     bool expected = new GregorianCalendar().IsLeapDay(year, month, day, era);
     Assert.Equal(expected, new KoreanCalendar().IsLeapDay(year + 2333, month, day, era));
 }
Beispiel #39
0
 private DateTime LunarToTime(DateTime time, int year, int month, int day)
 {
     LunarToGregorian(year, month, day, out int gy, out int gm, out int gd);
     return(GregorianCalendar.GetDefaultInstance().ToDateTime(gy, gm, gd, time.Hour, time.Minute, time.Second, time.Millisecond));
 }
Beispiel #40
0
        public IActionResult List(TouristRequestPayload payload)
        {
            var response = ResponseModelFactory.CreateResultInstance;

            using (_dbContext)
            {
                var scentc = _dbContext.Scenic.Where(x => x.IsDeleted == 0).Select(x => new { x.ScenicUuid, x.ScenicName });
                if (!string.IsNullOrEmpty(payload.Kw))
                {
                    scentc = scentc.Where(x => x.ScenicName.Contains(payload.Kw.Trim()));
                }
                var scentcList = scentc.Paged(payload.CurrentPage, payload.PageSize).ToList();
                var totalCount = scentc.Count();

                var suuid = scentcList.Select(x => x.ScenicUuid).ToList();

                if (payload.SType == 1)
                {
                    List <TouristYearData> touristYearDatas = new List <TouristYearData>();

                    var listTOY = _dbContext.TouristOfYear.Where(x => suuid.Contains(x.ScenicUuid.Value)).OrderByDescending(x => x.Year).ToList();
                    var maxYear = _dbContext.TouristOfYear.Max(x => x.Year);
                    if (maxYear == null)
                    {
                        maxYear = DateTime.Now.Year;
                    }
                    for (int i = 0; i < scentcList.Count; i++)
                    {
                        var             toys            = listTOY.FindAll(x => x.ScenicUuid == scentcList[i].ScenicUuid).Take(10).ToList();
                        TouristYearData touristYearData = new TouristYearData
                        {
                            ScenicUuid = scentcList[i].ScenicUuid,
                            ScenicName = scentcList[i].ScenicName,
                            First      = ReturnYearData(toys, 0),
                            Second     = ReturnYearData(toys, 1),
                            Third      = ReturnYearData(toys, 2),
                            Fourth     = ReturnYearData(toys, 3),
                            Fifth      = ReturnYearData(toys, 4),
                            Sixth      = ReturnYearData(toys, 5),
                            Seventh    = ReturnYearData(toys, 6),
                            Eighth     = ReturnYearData(toys, 7),
                            Ninth      = ReturnYearData(toys, 8),
                            Tenth      = ReturnYearData(toys, 9),
                            Sum        = toys.Sum(x => (long)x.Num.Value),
                        };

                        touristYearDatas.Add(touristYearData);
                    }
                    response.SetData(new { maxYear, touristYearDatas, totalCount });
                    return(Ok(response));
                }
                else if (payload.SType == 2)
                {
                    List <TouristMonthData> touristMonthDatas = new List <TouristMonthData>();
                    var listTOM = _dbContext.TouristOfMonth.Where(x => x.Year.Value == payload.year && suuid.Contains(x.ScenicUuid.Value)).OrderBy(x => x.Month).ToList();

                    for (int i = 0; i < scentcList.Count; i++)
                    {
                        var toms = listTOM.FindAll(x => x.ScenicUuid == scentcList[i].ScenicUuid);
                        TouristMonthData touristMonthData = new TouristMonthData()
                        {
                            ScenicUuid = scentcList[i].ScenicUuid,
                            ScenicName = scentcList[i].ScenicName,

                            Jan = ReturnMonthData(toms, 1),
                            Feb = ReturnMonthData(toms, 2),
                            Mar = ReturnMonthData(toms, 3),
                            Apr = ReturnMonthData(toms, 4),
                            May = ReturnMonthData(toms, 5),
                            Jun = ReturnMonthData(toms, 6),
                            Jul = ReturnMonthData(toms, 7),
                            Aug = ReturnMonthData(toms, 8),
                            Sep = ReturnMonthData(toms, 9),
                            Oct = ReturnMonthData(toms, 10),
                            Nov = ReturnMonthData(toms, 11),
                            Dec = ReturnMonthData(toms, 12),
                            Sum = toms.Sum(x => (long)x.Num),
                        };
                        touristMonthDatas.Add(touristMonthData);
                    }
                    response.SetData(new { touristMonthDatas, totalCount });
                    return(Ok(response));
                }
                else if (payload.SType == 3)
                {
                    GregorianCalendar gc = new GregorianCalendar();
                    //本月开始时间
                    DateTime sDate = new DateTime(payload.year, payload.Month, 1);
                    //本月结束时间
                    DateTime eDate = sDate.AddMonths(1).AddDays(-1);
                    //开始时间所在周数
                    int sWeekOfYear = gc.GetWeekOfYear(sDate, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
                    //结束时间所在周数
                    int eWeekOfYear = gc.GetWeekOfYear(eDate, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
                    //获取开始时间的本周周一时间
                    DateTime startWeek = DateTime.Now;
                    if (sDate.DayOfWeek == 0)
                    {
                        startWeek = sDate.AddDays(-6);
                    }
                    else
                    {
                        startWeek = sDate.AddDays(1 - (int)sDate.DayOfWeek);
                    }

                    //通过周一时间获取开始周数到结束周数的各个周区间,作为显示列名
                    List <string> columns = new List <string>();
                    for (int i = 0; i <= eWeekOfYear - sWeekOfYear; i++)
                    {
                        var s = startWeek.AddDays(i * 7);
                        var e = s.AddDays(6);
                        columns.Add(s.ToString("MM/dd") + "-" + e.ToString("MM/dd"));
                    }

                    List <TouristWeekData> touristWeekDatas = new List <TouristWeekData>();
                    var listTOW = _dbContext.TouristOfWeek.Where(x => x.Year.Value == payload.year && x.Weekend >= sWeekOfYear && x.Weekend <= eWeekOfYear && suuid.Contains(x.ScenicUuid.Value)).OrderBy(x => x.Weekend).ToList();
                    for (int i = 0; i < scentcList.Count; i++)
                    {
                        var             tows            = listTOW.FindAll(x => x.ScenicUuid == scentcList[i].ScenicUuid);
                        TouristWeekData touristWeekData = new TouristWeekData()
                        {
                            ScenicUuid = scentcList[i].ScenicUuid,
                            ScenicName = scentcList[i].ScenicName,
                            First      = ReturnWeekData(tows, sWeekOfYear),
                            Second     = ReturnWeekData(tows, sWeekOfYear + 1),
                            Third      = ReturnWeekData(tows, sWeekOfYear + 2),
                            Fourth     = ReturnWeekData(tows, sWeekOfYear + 3),
                            Sum        = tows.Sum(x => (long)x.Num),
                        };
                        if (eWeekOfYear - sWeekOfYear >= 4)
                        {
                            touristWeekData.Fifth = ReturnWeekData(tows, sWeekOfYear + 4);
                        }
                        else
                        {
                            touristWeekData.Fifth = null;
                        }
                        if (eWeekOfYear - sWeekOfYear == 5)
                        {
                            touristWeekData.Sixth = ReturnWeekData(tows, sWeekOfYear + 5);
                        }
                        else
                        {
                            touristWeekData.Sixth = null;
                        }

                        touristWeekDatas.Add(touristWeekData);
                    }

                    response.SetData(new { eWeekOfYear, sWeekOfYear, touristWeekDatas, columns, totalCount });

                    return(Ok(response));
                }
                else if (payload.SType == 4)
                {
                    int days = DateTime.DaysInMonth(payload.year, payload.Month);
                    List <TouristDayData> touristDayDatas = new List <TouristDayData>();
                    var listTOD = _dbContext.TouristOfDay.Where(x => x.Year.Value == payload.year && x.Month == payload.Month && suuid.Contains(x.ScenicUuid.Value)).OrderBy(x => x.Day).ToList();

                    for (int i = 0; i < scentcList.Count; i++)
                    {
                        var            tods           = listTOD.FindAll(x => x.ScenicUuid == scentcList[i].ScenicUuid);
                        TouristDayData touristDayData = new TouristDayData()
                        {
                            ScenicUuid     = scentcList[i].ScenicUuid,
                            ScenicName     = scentcList[i].ScenicName,
                            First          = ReturnDayData(tods, 1),
                            Second         = ReturnDayData(tods, 2),
                            Third          = ReturnDayData(tods, 3),
                            Fourth         = ReturnDayData(tods, 4),
                            Fifth          = ReturnDayData(tods, 5),
                            Sixth          = ReturnDayData(tods, 6),
                            Seventh        = ReturnDayData(tods, 7),
                            Eighth         = ReturnDayData(tods, 8),
                            Ninth          = ReturnDayData(tods, 9),
                            Tenth          = ReturnDayData(tods, 10),
                            Eleventh       = ReturnDayData(tods, 11),
                            Twelfth        = ReturnDayData(tods, 12),
                            Thirteenth     = ReturnDayData(tods, 13),
                            Fourteenth     = ReturnDayData(tods, 14),
                            Fifteenth      = ReturnDayData(tods, 15),
                            Sixteenth      = ReturnDayData(tods, 16),
                            Seventeenth    = ReturnDayData(tods, 17),
                            Eighteenth     = ReturnDayData(tods, 18),
                            Nineteenth     = ReturnDayData(tods, 19),
                            Twentieth      = ReturnDayData(tods, 20),
                            Twenty_first   = ReturnDayData(tods, 21),
                            Twenty_second  = ReturnDayData(tods, 22),
                            Twenty_third   = ReturnDayData(tods, 23),
                            Twenty_fourth  = ReturnDayData(tods, 24),
                            Twenty_fifth   = ReturnDayData(tods, 25),
                            Twenty_sixth   = ReturnDayData(tods, 26),
                            Twenty_seventh = ReturnDayData(tods, 27),
                            Twenty_eighth  = ReturnDayData(tods, 28),
                            Twenty_ninth   = ReturnDayData(tods, 29),
                            Thirtieth      = ReturnDayData(tods, 30),
                            Thirty_first   = ReturnDayData(tods, 31),
                            Sum            = listTOD.Sum(x => (long)x.Num),
                        };
                        touristDayDatas.Add(touristDayData);
                    }
                    response.SetData(new { days, touristDayDatas, totalCount });


                    return(Ok(response));
                }
                else
                {
                    return(Ok(null));
                }

                //string year = DateTime.Now.Year.ToString();

                //if (!string.IsNullOrEmpty(payload.year))
                //    year = payload.year;
                //var query = from p in _dbContext.Tourist
                //            where p.TouristTime.Contains(year)
                //            group p by new
                //            {
                //                p.ScenicName
                //            }
                //            into g
                //            select new
                //            {
                //                ScenicName = g.Key.ScenicName,
                //                Count = g.Count(),
                //            };
                //var query2 = from p in query
                //             select new
                //             {
                //                 ScenicName = p.ScenicName,
                //                 Count = p.Count,
                //                 Jan = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-01")),
                //                 Feb = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-02")),
                //                 Mar = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-03")),
                //                 Apr = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-04")),
                //                 May = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-05")),
                //                 Jun = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-06")),
                //                 Jul = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-07")),
                //                 Aug = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-08")),
                //                 Sep = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-09")),
                //                 Oct = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-10")),
                //                 Nov = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-11")),
                //                 Dec = _dbContext.Tourist.Count(x => x.ScenicName == p.ScenicName && x.TouristTime.Contains(year + "-12")),
                //             };


                //if (!string.IsNullOrEmpty(payload.Kw))
                //{
                //    query2 = query2.Where(x => x.ScenicName.Contains(payload.Kw.Trim()));
                //}


                //var list = query2.Paged(payload.CurrentPage, payload.PageSize).ToList();

                //totalCount = query2.Count();

                //response.SetData(list, totalCount);
                //return Ok(response);
            }
        }
Beispiel #41
0
        public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context)
        {
            ValidateArguments(arguments, 2);
            var numDate1 = ArgToDecimal(arguments, 0);
            var numDate2 = ArgToDecimal(arguments, 1);
            var dt1      = ExtensionMethods.FromOADate(numDate1);
            var dt2      = ExtensionMethods.FromOADate(numDate2);

            var calcType = Days360Calctype.Us;

            if (arguments.Count() > 2)
            {
                var european = ArgToBool(arguments, 2);
                if (european)
                {
                    calcType = Days360Calctype.European;
                }
            }

            var startYear  = dt1.Year;
            var startMonth = dt1.Month;
            var startDay   = dt1.Day;
            var endYear    = dt2.Year;
            var endMonth   = dt2.Month;
            var endDay     = dt2.Day;

            if (calcType == Days360Calctype.European)
            {
                if (startDay == 31)
                {
                    startDay = 30;
                }
                if (endDay == 31)
                {
                    endDay = 30;
                }
            }
            else
            {
                var calendar   = new GregorianCalendar();
                var nDaysInFeb = calendar.IsLeapYear(dt1.Year) ? 29 : 28;

                // If the investment is EOM and (Date1 is the last day of February) and (Date2 is the last day of February), then change D2 to 30.
                if (startMonth == 2 && startDay == nDaysInFeb && endMonth == 2 && endDay == nDaysInFeb)
                {
                    endDay = 30;
                }
                // If the investment is EOM and (Date1 is the last day of February), then change D1 to 30.
                if (startMonth == 2 && startDay == nDaysInFeb)
                {
                    startDay = 30;
                }
                // If D2 is 31 and D1 is 30 or 31, then change D2 to 30.
                if (endDay == 31 && (startDay == 30 || startDay == 31))
                {
                    endDay = 30;
                }
                // If D1 is 31, then change D1 to 30.
                if (startDay == 31)
                {
                    startDay = 30;
                }
            }
            var result = (endYear * 12 * 30 + endMonth * 30 + endDay) - (startYear * 12 * 30 + startMonth * 30 + startDay);

            return(CreateResult(result, DataType.Integer));
        }
Beispiel #42
0
        // Token: 0x06001FBC RID: 8124 RVA: 0x000B7720 File Offset: 0x000B5920
        public void RenderMonth(TextWriter output)
        {
            Calendar calendar     = new GregorianCalendar();
            int      weekStartDay = (int)this.sessionContext.WeekStartDay;

            Utilities.IsFlagSet(this.features, 16);
            this.dates = new DateTime[42];
            DateTime dateTime = (DateTime)DateTimeUtilities.GetLocalTime().Date;
            int      num      = -this.offset;

            for (int i = 0; i < 42; i++)
            {
                this.dates[i] = calendar.AddDays(this.firstDayInCurrentMonth, num);
                num++;
            }
            DateTime dateTime2 = (DateTime)this.month;

            output.Write("<div id=\"div");
            output.Write(calendar.GetMonth(dateTime2));
            output.Write(calendar.GetYear(dateTime2));
            output.Write("\"");
            output.Write(" y=");
            output.Write(calendar.GetYear(dateTime2));
            output.Write(" m=");
            output.Write(calendar.GetMonth(dateTime2));
            output.Write(" class=\"dpMonth\">");
            this.RenderHeader(output, calendar, dateTime2);
            int num2 = this.dates.Length / 7;

            this.RenderDaysOfWeek(output, weekStartDay);
            int num3  = 0;
            int num4  = calendar.GetMonth(dateTime2);
            int year  = calendar.GetYear(dateTime2);
            int num5  = calendar.GetMonth(this.dates[num3]);
            int year2 = calendar.GetYear(this.dates[num3]);

            for (int j = 0; j < num2; j++)
            {
                output.Write("<div id=\"divWeek");
                output.Write(j);
                if (Utilities.IsFlagSet(this.features, 16) || Utilities.IsFlagSet(this.features, 2))
                {
                    output.Write("\" class=\"dpWeekWp\">");
                }
                else
                {
                    output.Write("\" class=\"dpWeek\">");
                }
                if (Utilities.IsFlagSet(this.features, 16) || Utilities.IsFlagSet(this.features, 2))
                {
                    int weekOfYear = calendar.GetWeekOfYear(this.dates[num3], this.sessionContext.FirstWeekOfYear, (DayOfWeek)weekStartDay);
                    output.Write("<div");
                    output.Write(" w=");
                    output.Write(weekOfYear);
                    output.Write(" class=\"");
                    if (Utilities.IsFlagSet(this.features, 2))
                    {
                        output.Write("dpWeekNum ");
                    }
                    if (Utilities.IsFlagSet(this.features, 16))
                    {
                        output.Write("dpWeekPkr");
                    }
                    output.Write("\"");
                    if (Utilities.IsFlagSet(this.features, 16))
                    {
                        output.Write(" title=\"");
                        output.Write(SanitizedHtmlString.FromStringId(-1811092250));
                        output.Write("\">");
                    }
                    else
                    {
                        output.Write('>');
                    }
                    if (Utilities.IsFlagSet(this.features, 2))
                    {
                        output.Write(weekOfYear);
                    }
                    else
                    {
                        output.Write("&nbsp;");
                    }
                    output.Write("</div>");
                }
                for (int k = 0; k < 7; k++)
                {
                    bool flag = this.IsSelected(num3);
                    output.Write("<div");
                    if (flag)
                    {
                        output.Write(" id=s");
                    }
                    if (year2 != year)
                    {
                        output.Write(" y=");
                        output.Write(year2);
                    }
                    if (num5 != num4)
                    {
                        output.Write(" m=");
                        output.Write(num5);
                    }
                    output.Write(" class='");
                    if (DateTime.Compare(dateTime, this.dates[num3].Date) == 0)
                    {
                        output.Write(" dpToday");
                    }
                    output.Write(Utilities.IsFlagSet(this.features, 32) ? " dpDayDdM" : " dpDay");
                    if (flag)
                    {
                        output.Write(" dpSel ");
                    }
                    if (this.indexMonthStart > num3 || this.indexMonthEnd < num3)
                    {
                        output.Write(" dpPOrN");
                    }
                    if (this.busyType != null && this.busyType[num3] == BusyType.Busy)
                    {
                        output.Write(" b");
                    }
                    output.Write("'>");
                    string text = DateTimeUtilities.GetDaysFormat(this.sessionContext.DateFormat);
                    if (text == null)
                    {
                        text = "%d";
                    }
                    output.Write("<span class=\"dpDayNum\">");
                    output.Write(this.dates[num3].ToString(text));
                    output.Write("</span>");
                    output.Write("</div>");
                    num3++;
                    if (num3 < this.dates.Length)
                    {
                        num5  = calendar.GetMonth(this.dates[num3]);
                        year2 = calendar.GetYear(this.dates[num3]);
                    }
                }
                output.Write("</div>");
            }
            this.RenderTodayButtons(output, calendar, dateTime);
            this.RenderMonthList(output);
            output.Write("</div>");
        }
Beispiel #43
0
        public void GetLeapMonth()
        {
            GregorianCalendar gc = new GregorianCalendar();

            Assert.AreEqual(0, gc.GetLeapMonth(2007), "#1-1");
            Assert.AreEqual(0, gc.GetLeapMonth(2008), "#1-2");
            Assert.AreEqual(0, gc.GetLeapMonth(2100), "#1-3");
            Assert.AreEqual(0, gc.GetLeapMonth(2000), "#1-4");

            JulianCalendar jc = new JulianCalendar();

            Assert.AreEqual(0, jc.GetLeapMonth(2007), "#2-1");
            Assert.AreEqual(0, jc.GetLeapMonth(2008), "#2-2");
            Assert.AreEqual(0, jc.GetLeapMonth(2100), "#2-3");
            Assert.AreEqual(0, jc.GetLeapMonth(2000), "#2-4");
            Assert.AreEqual(0, jc.GetLeapMonth(2009), "#2-5");
            Assert.AreEqual(0, jc.GetLeapMonth(2010), "#2-6");

            HebrewCalendar hc = new HebrewCalendar();

            // 3rd, 6th, 8th, 11th 14th and 17th year in every 19 are leap.
            // 5339 % 19 = 0.
            Assert.AreEqual(0, hc.GetLeapMonth(5343), "#3-1");
            Assert.AreEqual(0, hc.GetLeapMonth(5344), "#3-2");
            Assert.AreEqual(7, hc.GetLeapMonth(5345), "#3-3");
            Assert.AreEqual(0, hc.GetLeapMonth(5346), "#3-4");
            Assert.AreEqual(7, hc.GetLeapMonth(5347), "#3-5");
            Assert.AreEqual(0, hc.GetLeapMonth(5348), "#3-6");
            Assert.AreEqual(0, hc.GetLeapMonth(5349), "#3-7");

            ThaiBuddhistCalendar tc = new ThaiBuddhistCalendar();

            Assert.AreEqual(0, tc.GetLeapMonth(2520), "#4-1");
            Assert.AreEqual(0, tc.GetLeapMonth(2521), "#4-2");
            Assert.AreEqual(0, tc.GetLeapMonth(2522), "#4-3");
            Assert.AreEqual(0, tc.GetLeapMonth(2523), "#4-4");

            ChineseLunisolarCalendar cc = new ChineseLunisolarCalendar();

            Assert.AreEqual(0, cc.GetLeapMonth(2000), "#5-1");
            Assert.AreEqual(5, cc.GetLeapMonth(2001), "#5-2");
            Assert.AreEqual(0, cc.GetLeapMonth(2002), "#5-3");
            Assert.AreEqual(0, cc.GetLeapMonth(2003), "#5-4");
            Assert.AreEqual(3, cc.GetLeapMonth(2004), "#5-5");
            Assert.AreEqual(0, cc.GetLeapMonth(2005), "#5-6");
            Assert.AreEqual(8, cc.GetLeapMonth(2006), "#5-7");
            Assert.AreEqual(0, cc.GetLeapMonth(2007), "#5-8");
            Assert.AreEqual(0, cc.GetLeapMonth(2008), "#5-9");
            Assert.AreEqual(6, cc.GetLeapMonth(2009), "#5-10");
            Assert.AreEqual(0, cc.GetLeapMonth(2010), "#5-11");
            Assert.AreEqual(0, cc.GetLeapMonth(2011), "#5-12");
            Assert.AreEqual(5, cc.GetLeapMonth(2012), "#5-13");
            Assert.AreEqual(0, cc.GetLeapMonth(2013), "#5-14");
            Assert.AreEqual(10, cc.GetLeapMonth(2014), "#5-15");
            Assert.AreEqual(0, cc.GetLeapMonth(2015), "#5-16");
            Assert.AreEqual(0, cc.GetLeapMonth(2016), "#5-17");
            Assert.AreEqual(7, cc.GetLeapMonth(2017), "#5-18");
            Assert.AreEqual(0, cc.GetLeapMonth(2018), "#5-19");
            Assert.AreEqual(0, cc.GetLeapMonth(2019), "#5-20");

            KoreanLunisolarCalendar kc = new KoreanLunisolarCalendar();

            Assert.AreEqual(0, kc.GetLeapMonth(2000), "#6-1");
            Assert.AreEqual(5, kc.GetLeapMonth(2001), "#6-2");
            Assert.AreEqual(0, kc.GetLeapMonth(2002), "#6-3");
            Assert.AreEqual(0, kc.GetLeapMonth(2003), "#6-4");
            Assert.AreEqual(3, kc.GetLeapMonth(2004), "#6-5");
            Assert.AreEqual(0, kc.GetLeapMonth(2005), "#6-6");
            Assert.AreEqual(8, kc.GetLeapMonth(2006), "#6-7");
            Assert.AreEqual(0, kc.GetLeapMonth(2007), "#6-8");
            Assert.AreEqual(0, kc.GetLeapMonth(2008), "#6-9");
            Assert.AreEqual(6, kc.GetLeapMonth(2009), "#6-10");
            Assert.AreEqual(0, kc.GetLeapMonth(2010), "#6-11");
            Assert.AreEqual(0, kc.GetLeapMonth(2011), "#6-12");
            Assert.AreEqual(4, kc.GetLeapMonth(2012));       // off from cn by 1, "#6-13");
            Assert.AreEqual(0, kc.GetLeapMonth(2013), "#6-14");
            Assert.AreEqual(10, kc.GetLeapMonth(2014), "#6-15");
            Assert.AreEqual(0, kc.GetLeapMonth(2015), "#6-16");
            Assert.AreEqual(0, kc.GetLeapMonth(2016), "#6-17");
            Assert.AreEqual(6, kc.GetLeapMonth(2017));       // off from cn by 1, "#6-18");
            Assert.AreEqual(0, kc.GetLeapMonth(2018), "#6-19");
            Assert.AreEqual(0, kc.GetLeapMonth(2019), "#6-20");
        }
Beispiel #44
0
        public static DateTime NextDayOfWeek(this DateTime dt, DayOfWeek day)
        {
            var d = new GregorianCalendar().AddDays(dt, -((int)dt.DayOfWeek) + (int)day);

            return((d.Day < dt.Day) ? d.AddDays(7) : d);
        }
Beispiel #45
0
        /// <summary>
        /// 获取某一日期是该年中的第几周
        /// </summary>
        /// <param name="dt">日期</param>
        /// <returns>该日期在该年中的周数</returns>
        public static int GetWeekOfYear(DateTime dt)
        {
            var gc = new GregorianCalendar();

            return(gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday));
        }
 public void GetDaysInMonth(int year, int month, int era)
 {
     int expected = new GregorianCalendar().GetDaysInMonth(year, month, era);
     Assert.Equal(expected, new KoreanCalendar().GetDaysInMonth(year + 2333, month, era));
 }
Beispiel #47
0
        internal static bool CreateCalendar(Calendars calendarType, out Calendar calendar)
        {
            calendar = null;
            bool result = false;

            switch (calendarType)
            {
            case Calendars.Default:
            case Calendars.Gregorian:
                calendar = new GregorianCalendar();
                break;

            case Calendars.GregorianArabic:
                result   = true;
                calendar = new GregorianCalendar(GregorianCalendarTypes.Arabic);
                break;

            case Calendars.GregorianMiddleEastFrench:
                result   = true;
                calendar = new GregorianCalendar(GregorianCalendarTypes.MiddleEastFrench);
                break;

            case Calendars.GregorianTransliteratedEnglish:
                result   = true;
                calendar = new GregorianCalendar(GregorianCalendarTypes.TransliteratedEnglish);
                break;

            case Calendars.GregorianTransliteratedFrench:
                result   = true;
                calendar = new GregorianCalendar(GregorianCalendarTypes.TransliteratedFrench);
                break;

            case Calendars.GregorianUSEnglish:
                result   = true;
                calendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
                break;

            case Calendars.Hebrew:
                calendar = new HebrewCalendar();
                break;

            case Calendars.Hijri:
                calendar = new HijriCalendar();
                break;

            case Calendars.Japanese:
                calendar = new JapaneseCalendar();
                break;

            case Calendars.Julian:
                calendar = new JulianCalendar();
                break;

            case Calendars.Korean:
                calendar = new KoreanCalendar();
                break;

            case Calendars.Taiwan:
                calendar = new TaiwanCalendar();
                break;

            case Calendars.ThaiBuddhist:
                calendar = new ThaiBuddhistCalendar();
                break;
            }
            return(result);
        }
 public void ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
 {
     DateTime expected = new GregorianCalendar().ToDateTime(year, month, day, hour, minute, second, millisecond, era);
     Assert.Equal(expected, new ThaiBuddhistCalendar().ToDateTime(year + 543, month, day, hour, minute, second, millisecond, era));
 }
Beispiel #49
0
        private string BuildInFunc(Plot plt, string name, DateTime dt, ServerSQL dataSQL)
        {
            Calendar cal;
            int      formatPV;

            switch (name.ToUpper())
            {
            case "PRINTTIME": return(DateTime.Now.ToString("dd.MM.yyyy ddd HH:mm:ss"));

            case "PRINTDAYSTART": return(dt.ToString("dd.MM.yyyy ddd 00:00:00"));

            case "PRINTDAYFINISH": return(dt.ToString("dd.MM.yyyy ddd 23:59:59"));

            case "PRINTSHIFT1START": return(dt.ToString("dd.MM.yyyy ddd 08:00:00"));

            case "PRINTSHIFT1FINISH": return(dt.ToString("dd.MM.yyyy ddd 19:59:59"));

            case "PRINTPREVDAYSTART": return(dt.AddDays(-1).ToString("dd.MM.yyyy ddd 00:00:00"));

            case "PRINTPREVDAYFINISH": return(dt.AddDays(-1).ToString("dd.MM.yyyy ddd 23:59:59"));

            case "PRINTSHIFT2START": return(dt.AddDays(-1).ToString("dd.MM.yyyy ddd 20:00:00"));

            case "PRINTSHIFT2FINISH": return(dt.ToString("dd.MM.yyyy ddd 07:59:59"));

            case "PRINTMONTHSTART": return(dt.ToString("01.MM.yyyy ddd 00:00:00"));

            case "PRINTMONTHFINISH":
                cal = new GregorianCalendar(GregorianCalendarTypes.Localized);
                return(dt.ToString(String.Format("{0}.MM.yyyy ddd 23:59:59",
                                                 cal.GetDaysInMonth(dt.Year, dt.Month))));

            case "PRINTPREVMONTHSTART": return(dt.AddMonths(-1).ToString("01.MM.yyyy ddd 00:00:00"));

            case "PRINTPREVMONTHFINISH":
                cal = new GregorianCalendar(GregorianCalendarTypes.Localized);
                return(dt.AddMonths(-1).ToString(String.Format("{0}.MM.yyyy ddd 23:59:59",
                                                               cal.GetDaysInMonth(dt.AddMonths(-1).Year, dt.AddMonths(-1).Month))));

            default:
                string value = name.ToUpper();
                if (value.StartsWith("HOUR(") && value.EndsWith(")"))     // [{HOUR(N, POINT.PV)}] где N - offset (часов)
                {
                    string[] args =
                        value.Substring(5, value.IndexOf(')') - 5).Split(new char[] { ',' });
                    if (args.Length == 2)
                    {
                        double offset;
                        formatPV = getFormatPV(args[1].Trim(), plt, dataSQL);
                        if (double.TryParse(args[0].Trim(), out offset))
                        {
                            return(Data.GetHourData(args[1].Trim(), dt.AddHours(-offset), dataSQL,
                                                    formatPV));
                        }
                        else
                        {
                            return(value.Substring(0, value.IndexOf(',') - 1) + "?");
                        }
                    }
                    else
                    {
                        return("HOUR(?,?)");
                    }
                }
                else if (value.StartsWith("DAILY(") && value.EndsWith(")"))     // [{DAILY(N, POINT.PV)}] где N - offset (дней)
                {
                    string[] args =
                        value.Substring(6, value.IndexOf(')') - 6).Split(new char[] { ',' });
                    if (args.Length == 2)
                    {
                        double offset;
                        formatPV = getFormatPV(args[1].Trim(), plt, dataSQL);
                        if (double.TryParse(args[0].Trim(), out offset))
                        {
                            return(Data.GetDailyData(args[1].Trim(), dt.AddDays(-offset), dataSQL,
                                                     formatPV));
                        }
                        else
                        {
                            return(value.Substring(0, value.IndexOf(',') - 1) + "?");
                        }
                    }
                    else
                    {
                        return("DAILY(?,?)");
                    }
                }
                else if (value.StartsWith("MONTH(") && value.EndsWith(")"))     // [{MONTH(N, POINT.PV)}] где N - offset (месяцев)
                {
                    string[] args =
                        value.Substring(6, value.IndexOf(')') - 6).Split(new char[] { ',' });
                    if (args.Length == 2)
                    {
                        int offset;
                        formatPV = getFormatPV(args[1].Trim(), plt, dataSQL);
                        if (int.TryParse(args[0].Trim(), out offset))
                        {
                            return(Data.GetMonthData(args[1].Trim(), dt.AddMonths(-offset), dataSQL,
                                                     formatPV));
                        }
                        else
                        {
                            return(value.Substring(0, value.IndexOf(',') - 1) + "?");
                        }
                    }
                    else
                    {
                        return("MONTH(?,?)");
                    }
                }
                return("{" + name + "?}");
            }
        }