public void HoursTest()
 {
     ExtendedFormat format = new ExtendedFormat("* 5 * * *");
     int[] hours = format.GetHours();
     Assert.AreEqual(1, hours.Length);
     Assert.AreEqual(5, hours[0]);
 }
 public void MinutesTest()
 {
     ExtendedFormat format = new ExtendedFormat("5 * * * *");
     int[] minutes = format.GetMinutes();
     Assert.AreEqual(1, minutes.Length);
     Assert.AreEqual(5, minutes[0]);
 }
Esempio n. 3
0
 public void ExpirationWithAllWildCardsWillExpireAfterOneMinute()
 {
     ExtendedFormat oneMinuteExpiration = new ExtendedFormat("* * * * *");
     DateTime baseTime = DateTime.Parse("5/1/2004 12:00:00");
     DateTime expirationTime = DateTime.Parse("5/1/2004 12:01:00");
     Assert.IsTrue(oneMinuteExpiration.IsExpired(baseTime, expirationTime));
 }
Esempio n. 4
0
 public void DaysOfWeekTest()
 {
     ExtendedFormat format = new ExtendedFormat("* * * * 5");
     int[] daysOfWeek = format.GetDaysOfWeek();
     Assert.AreEqual(1, daysOfWeek.Length);
     Assert.AreEqual(5, daysOfWeek[0]);
 }
Esempio n. 5
0
 public void DaysTest()
 {
     ExtendedFormat format = new ExtendedFormat("* * 5 * *");
     int[] days = format.GetDays();
     Assert.AreEqual(1, days.Length);
     Assert.AreEqual(5, days[0]);
 }
Esempio n. 6
0
        private string TryGetFormulaString(XlsBiffStream biffStream, ExtendedFormat effectiveStyle)
        {
            var rec = biffStream.Read();

            if (rec != null && rec.Id == BIFFRECORDTYPE.SHAREDFMLA)
            {
                rec = biffStream.Read();
            }

            if (rec != null && rec.Id == BIFFRECORDTYPE.STRING)
            {
                var stringRecord    = (XlsBiffFormulaString)rec;
                var formulaEncoding = GetFont(effectiveStyle.FontIndex)?.ByteStringEncoding ?? Encoding; // Workbook.GetFontEncodingFromXF(xFormat) ?? Encoding;
                return(stringRecord.GetValue(formulaEncoding));
            }

            // Bad data - could not find a string following the formula
            return(null);
        }
Esempio n. 7
0
        internal void AddXf(XlsBiffXF xf)
        {
            var extendedFormat = new ExtendedFormat()
            {
                FontIndex           = xf.Font,
                NumberFormatIndex   = xf.Format,
                Locked              = xf.IsLocked,
                Hidden              = xf.IsHidden,
                HorizontalAlignment = xf.HorizontalAlignment,
                IndentLevel         = xf.IndentLevel,
                ParentCellStyleXf   = xf.ParentCellStyleXf,
            };

            // The workbook holds two kinds of XF records: Cell XFs, and Cell Style XFs.
            // In the binary XLS format, both kinds of XF records are saved in a single list,
            // whereas the XLSX format has two separate lists - like the CommonWorkbook internals.
            // The Cell XFs hold indexes into the Cell Style XF list, so adding the XF in both lists
            // here to keep the indexes the same.
            ExtendedFormats.Add(extendedFormat);
            CellStyleExtendedFormats.Add(extendedFormat);
        }
Esempio n. 8
0
        public void Format_DictionaryOfAnonymousTypeWithPropertyAsStringList()
        {
            var dic = new Dictionary <int, object>()
            {
                { 100, new { LastName = "TORRES", Values = DS.List("1", "2", "3") } },
            };

            StringBuilder b      = new StringBuilder(1024);
            string        format = "LastName:{LastName}, Values:{Values}";

            var expected = @"LastName:TORRES, Values:[""1"", ""2"", ""3""]
";

            foreach (var v in dic.Values)
            {
                b.Append(ExtendedFormat.Format(v, format)).AppendLine();
            }
            var s = b.ToString();

            Assert.AreEqual(expected, b.ToString());
        }
 public void MultiMonthsTest()
 {
     ExtendedFormat format = new ExtendedFormat("* * * 5,1 *");
     int[] months = format.GetMonths();
     Assert.AreEqual(2, months.Length);
     Assert.AreEqual(5, months[0]);
     Assert.AreEqual(1, months[1]);
 }
 public CellStyleExtendedFormatRecord(ExtendedFormat extendedFormat)
 {
     ExtendedFormat = extendedFormat;
 }
 public void MonthsOutOfRangeTest()
 {
     ExtendedFormat format = new ExtendedFormat("* * * 13 *");
     Assert.IsNull(format);
 }
Esempio n. 12
0
        private object TryGetFormulaValue(XlsBiffStream biffStream, XlsBiffFormulaCell formulaCell, ExtendedFormat effectiveStyle)
        {
            return(formulaCell.FormulaType switch
            {
                XlsBiffFormulaCell.FormulaValueType.Boolean => formulaCell.BooleanValue,
                XlsBiffFormulaCell.FormulaValueType.Error => null,
                XlsBiffFormulaCell.FormulaValueType.EmptyString => string.Empty,
                XlsBiffFormulaCell.FormulaValueType.Number => TryConvertOADateTime(formulaCell.XNumValue, effectiveStyle.NumberFormatIndex),
                XlsBiffFormulaCell.FormulaValueType.String => TryGetFormulaString(biffStream, effectiveStyle),

                // Bad data or new formula value type
                _ => null,
            });
Esempio n. 13
0
 public void HoursTest()
 {
     ExtendedFormat format = new ExtendedFormat("* 5 * * *");
     Assert.AreEqual(1, format.Hours.Length);
     Assert.AreEqual(5, format.Hours[0]);
 }
 public void TestForBug353()
 {
     ExtendedFormat format = new ExtendedFormat("* * 29 * *");
     bool expired = format.IsExpired(new DateTime(2003, 2, 10, 10, 10, 0), new DateTime(2003, 3, 10, 10, 10, 0));
     Assert.IsTrue(expired, "Should have expired at end of month, even though there is no Feb. 29th");
 }
        public void CreateBadFormTest()
        {
            ExtendedFormat format = new ExtendedFormat("5 * * *");

            Assert.IsNull(format);
        }
 public void CreateBadFormTest()
 {
     ExtendedFormat format = new ExtendedFormat("5 * * *");
     Assert.IsNull(format);
 }
        public void MonthsOutOfRangeTest()
        {
            ExtendedFormat format = new ExtendedFormat("* * * 13 *");

            Assert.IsNull(format);
        }
        public void DaysOfWeekOutOfRangeTest()
        {
            ExtendedFormat format = new ExtendedFormat("* * * * 8");

            Assert.IsNull(format);
        }
 public void NullFormatThrowsException()
 {
     ExtendedFormat format = new ExtendedFormat(null);
 }
        public void HoursOutOfRangeTest()
        {
            ExtendedFormat format = new ExtendedFormat("* 25 * * *");

            Assert.IsNull(format);
        }
        public void MinutesOutOfRangeTest()
        {
            ExtendedFormat format = new ExtendedFormat("61 * * * *");

            Assert.IsNull(format);
        }
        public void NegativeFormatTest()
        {
            ExtendedFormat format = new ExtendedFormat("* * -3 * *");

            Assert.IsNull(format);
        }
 public void DaysOfWeekOutOfRangeTest()
 {
     ExtendedFormat format = new ExtendedFormat("* * * * 8");
     Assert.IsNull(format);
 }
Esempio n. 24
0
 public ExtendedFormatRecord(ExtendedFormat extendedFormat)
 {
     ExtendedFormat = extendedFormat;
 }
 public void IsExpiredTest()
 {
     ExtendedFormat format = new ExtendedFormat("1 * * * *");
     bool expired = format.IsExpired(DateTime.Now.Subtract(new TimeSpan(1, 1, 2)), DateTime.Now);
     Assert.IsTrue(expired);
 }
Esempio n. 26
0
        private object TryGetFormulaValue(XlsBiffStream biffStream, XlsBiffFormulaCell formulaCell, ExtendedFormat effectiveStyle, out CellError?error)
        {
            error = null;
            switch (formulaCell.FormulaType)
            {
            case XlsBiffFormulaCell.FormulaValueType.Boolean: return(formulaCell.BooleanValue);

            case XlsBiffFormulaCell.FormulaValueType.Error:
                error = (CellError)formulaCell.ErrorValue;
                return(null);

            case XlsBiffFormulaCell.FormulaValueType.EmptyString: return(string.Empty);

            case XlsBiffFormulaCell.FormulaValueType.Number: return(TryConvertOADateTime(formulaCell.XNumValue, effectiveStyle.NumberFormatIndex));

            case XlsBiffFormulaCell.FormulaValueType.String: return(TryGetFormulaString(biffStream, effectiveStyle));

            // Bad data or new formula value type
            default: return(null);
            }
        }
 public void TestForBug352()
 {
     ExtendedFormat format = new ExtendedFormat("0 0 1 4 *");
     bool expired = format.IsExpired(new DateTime(2001, 4, 01, 00, 05, 0), new DateTime(2002, 3, 31, 23, 59, 0));
     Assert.IsFalse(expired, "Has not hit midnight, April 1st of next year yet");
 }
 public void NullFormatThrowsException()
 {
     ExtendedFormat format = new ExtendedFormat(null);
 }
 public void SecondsAreRoundedOutBeforePerformingPerMinuteExpirations()
 {
     ExtendedFormat oneMinuteExpiration = new ExtendedFormat("* * * * *");
     DateTime baseTime = DateTime.Parse("5/1/2004 12:00:59");
     DateTime expirationTime = DateTime.Parse("5/1/2004 12:01:01");
     Assert.IsTrue(oneMinuteExpiration.IsExpired(baseTime, expirationTime));
 }
Esempio n. 30
0
 public void MultiMinutesTest()
 {
     ExtendedFormat format = new ExtendedFormat("5,1 * * * *");
     Assert.AreEqual(2, format.Minutes.Length);
     Assert.AreEqual(5, format.Minutes[0]);
     Assert.AreEqual(1, format.Minutes[1]);
 }
 public void NegativeFormatTest()
 {
     ExtendedFormat format = new ExtendedFormat("* * -3 * *");
     Assert.IsNull(format);
 }
Esempio n. 32
0
 public void MultiMonthsTest()
 {
     ExtendedFormat format = new ExtendedFormat("* * * 5,1 *");
     Assert.AreEqual(2, format.Months.Length);
     Assert.AreEqual(5, format.Months[0]);
     Assert.AreEqual(1, format.Months[1]);
 }
 public void MinutesOutOfRangeTest()
 {
     ExtendedFormat format = new ExtendedFormat("61 * * * *");
     Assert.IsNull(format);
 }
Esempio n. 34
0
 public void DaysOfWeekTest()
 {
     ExtendedFormat format = new ExtendedFormat("* * * * 5");
     Assert.AreEqual(1, format.DaysOfWeek.Length);
     Assert.AreEqual(5, format.DaysOfWeek[0]);
 }
 public void HoursOutOfRangeTest()
 {
     ExtendedFormat format = new ExtendedFormat("* 25 * * *");
     Assert.IsNull(format);
 }
Esempio n. 36
0
 public void DaysTest()
 {
     ExtendedFormat format = new ExtendedFormat("* * 5 * *");
     Assert.AreEqual(1, format.Days.Length);
     Assert.AreEqual(5, format.Days[0]);
 }