public void LastYearTest() { DateTime lastYear = new DateTime(2011, 12, 22); string expected = DateFormatConverter.DataConvert(lastYear); Assert.AreEqual("12/22/11", expected); }
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); } }
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); } }
private bool IsDateTime() { var isDateTime = new DateFormatConverter().Converter(textBox.Text) != DateTime.MinValue; return(isDateTime); }
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; }
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"); }
public void SetUp() { Converter = new DateFormatConverter(); }