Exemplo n.º 1
0
        public void LastYearTest()
        {
            DateTime lastYear = new DateTime(2011, 12, 22);
            string   expected = DateFormatConverter.DataConvert(lastYear);

            Assert.AreEqual("12/22/11", expected);
        }
Exemplo n.º 2
0
 public void ThisYearTest()
 {
     if (DateTime.Now.Month != 1 && DateTime.Now.Day != 1)
     {
         DateTime thisYear = new DateTime(DateTime.Now.Year, 1, 1);
         string   expected = DateFormatConverter.DataConvert(thisYear);
         Assert.AreEqual("Січ 1", expected);
     }
     else
     {
         DateTime thisYear = new DateTime(DateTime.Now.Year, 1, 2);
         string   expected = DateFormatConverter.DataConvert(thisYear);
         Assert.AreEqual("Січ 2", expected);
     }
 }
Exemplo n.º 3
0
        public void TodayTest()
        {
            DateTime today    = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 1);
            string   expected = DateFormatConverter.DataConvert(today);

            Assert.AreEqual("12:00 AM", expected);

            if (DateTime.Now.Month != 1)
            {
                today    = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, DateTime.Now.Day, 0, 0, 1);
                expected = DateFormatConverter.DataConvert(today);
                Assert.AreNotEqual("12:00 AM", expected);
            }
            else
            {
                today    = new DateTime(DateTime.Now.Year, DateTime.Now.Month + 1, DateTime.Now.Day, 0, 0, 1);
                expected = DateFormatConverter.DataConvert(today);
                Assert.AreNotEqual("12:00 AM", expected);
            }
        }
Exemplo n.º 4
0
        private bool IsDateTime()
        {
            var isDateTime = new DateFormatConverter().Converter(textBox.Text) != DateTime.MinValue;

            return(isDateTime);
        }
Exemplo n.º 5
0
 public static string ToString(DateTime?value)
 {
     return(value.HasValue ?
            DateFormatConverter.DataConvert(value.Value) :
            Localization.GetMessage("DateNotSpecified"));
 }
 private bool IsDateTime()
 {
     var isDateTime = new DateFormatConverter().Converter(textBox.Text) != DateTime.MinValue;
     return isDateTime;
 }
Exemplo n.º 7
0
        private void OutputLocaleDataFormats(DateTime date, bool dates, bool times, int style, String styleName)
        {
            IWorkbook workbook = new HSSFWorkbook();
            String    sheetName;

            if (dates)
            {
                if (times)
                {
                    sheetName = "DateTimes";
                }
                else
                {
                    sheetName = "Dates";
                }
            }
            else
            {
                sheetName = "Times";
            }
            ISheet sheet  = workbook.CreateSheet(sheetName);
            IRow   header = sheet.CreateRow(0);

            header.CreateCell(0).SetCellValue("locale");
            header.CreateCell(1).SetCellValue("DisplayName");
            header.CreateCell(2).SetCellValue("Excel " + styleName);
            header.CreateCell(3).SetCellValue("java.text.DateFormat");
            header.CreateCell(4).SetCellValue("Equals");
            header.CreateCell(5).SetCellValue("Java pattern");
            header.CreateCell(6).SetCellValue("Excel pattern");

            int rowNum = 1;

            foreach (CultureInfo locale in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                IRow row = sheet.CreateRow(rowNum++);

                row.CreateCell(0).SetCellValue(locale.ToString());
                row.CreateCell(1).SetCellValue(locale.DisplayName);

                string csharpDateFormatPattern;
                if (dates)
                {
                    if (times)
                    {
                        csharpDateFormatPattern = DateFormat.GetDateTimeInstance(style, style, locale);
                    }
                    else
                    {
                        csharpDateFormatPattern = DateFormat.GetDateInstance(style, locale);
                    }
                }
                else
                {
                    csharpDateFormatPattern = DateFormat.GetTimeInstance(style, locale);
                }

                //Excel Date Value
                ICell cell = row.CreateCell(2);

                cell.SetCellValue(date);
                ICellStyle cellStyle = row.Sheet.Workbook.CreateCellStyle();

                //String csharpDateFormatPattern = locale.DateTimeFormat.LongDatePattern;
                String excelFormatPattern = DateFormatConverter.Convert(locale, csharpDateFormatPattern);

                IDataFormat poiFormat = row.Sheet.Workbook.CreateDataFormat();
                cellStyle.DataFormat = (poiFormat.GetFormat(excelFormatPattern));
                cell.CellStyle       = (cellStyle);

                //C# Date value
                row.CreateCell(3).SetCellValue(date.ToString(csharpDateFormatPattern, locale.DateTimeFormat));



                // the formula returns TRUE is the formatted date in column C equals to the string in column D
                row.CreateCell(4).SetCellFormula("TEXT(C" + rowNum + ",G" + rowNum + ")=D" + rowNum);
                //C# pattern
                row.CreateCell(5).SetCellValue(csharpDateFormatPattern);
                //excel pattern
                row.CreateCell(6).SetCellValue(excelFormatPattern);
            }

            //FileInfo outputFile = TempFile.CreateTempFile("Locale" + sheetName + styleName, ".xlsx");
            string     filename     = "Locale" + sheetName + styleName + ".xls";
            FileStream outputStream = new FileStream(filename, FileMode.CreateNew);

            try
            {
                workbook.Write(outputStream);
            }
            finally
            {
                outputStream.Close();
            }
            System.Console.WriteLine("Open " + filename + " in Excel");
        }
Exemplo n.º 8
0
 public void SetUp()
 {
     Converter = new DateFormatConverter();
 }