public void TestDateTimeFormat() { string v = SqlFormat.DateTimeFormat(null); AssertAreEqual(v, "NULL", "Date nulle"); v = SqlFormat.DateTimeFormat(new DateTime(2000, 10, 23, 12, 30, 00, 100)); AssertAreEqual(v, "'2000-10-23T12:30:00'", "Date 23/10/2000 12h30:00.100"); v = SqlFormat.DateTimeFormat(new DateTime(2000, 10, 23, 12, 30, 00, 100), true); AssertAreEqual(v, "'2000-10-23T12:30:00'", "Date nullable 23/10/2000 12h30:00.100"); v = SqlFormat.DateTimeFormat(DateTime.MinValue); AssertAreEqual(v, "GETDATE()", "Date MinValue not Null"); v = SqlFormat.DateTimeFormat(DateTime.MinValue, true); AssertAreEqual(v, "NULL", "Date MinValue Null"); v = SqlFormat.DateTimeFormat(DateTime.MaxValue); AssertAreEqual(v, "GETDATE()", "Date MaxValue not Null"); v = SqlFormat.DateTimeFormat(new DateTime(1600, 1, 5), true); AssertAreEqual(v, "NULL", "Date 05/01/1600 inférieur à min SQL nullable"); v = SqlFormat.DateTimeFormat(new DateTime(9999, 12, 31, 23, 59, 59, 300), true); AssertAreEqual(v, "NULL", "Date 31/12/9999 23h59:59.300 supérieur à max SQL nullable"); DateTime?dt = null; v = SqlFormat.DateTimeFormat(dt); AssertAreEqual(v, "NULL", "Date? Null"); dt = new DateTime(2000, 10, 23, 12, 30, 00); v = SqlFormat.DateTimeFormat(dt); AssertAreEqual(v, "'2000-10-23T12:30:00'", "Date 23/10/2000 12h30"); // DateTime2 dt = null; v = SqlFormat.DateTime2Format(dt); AssertAreEqual(v, "NULL", "DateTime2? Null"); dt = new DateTime(2000, 10, 23, 12, 30, 00, 100); v = SqlFormat.DateTime2Format(dt); AssertAreEqual(v, "'2000-10-23T12:30:00.100'", "Date Time2 23/10/2000 12h30:00.100"); v = SqlFormat.DateTime2Format(new DateTime(2000, 10, 23, 12, 30, 00, 100), true); AssertAreEqual(v, "'2000-10-23T12:30:00.100'", "Date nullable Time2 23/10/2000 12h30:00.100"); // Heure Format DateTime pivot = SqlFormat.DatePivotHeure; AssertAreEqual(pivot, new DateTime(1900, 1, 1), "Heure Pivot base"); dt = null; v = SqlFormat.HeureFormat(dt); AssertAreEqual(v, "NULL", "Heure? dans datetime Null"); dt = new DateTime(2000, 10, 23, 12, 30, 00, 100); v = SqlFormat.HeureFormat(dt); AssertAreEqual(v, "'1900-01-01T12:30:00'", "Heure? dans datetime 23/10/2000 12h30:00.100"); v = SqlFormat.HeureFormat(new DateTime(2000, 10, 23, 12, 30, 00, 100), nullable: true); AssertAreEqual(v, "'1900-01-01T12:30:00'", "Heure? dans datetime nullable 23/10/2000 12h30:00.100"); // Heure dans DateTime2 dt = null; v = SqlFormat.HeureFormat(dt, SqlFormat.EFormatDate.DateTime2); AssertAreEqual(v, "NULL", "Heure? dans datetime2 Null"); dt = new DateTime(2000, 10, 23, 12, 30, 00, 100); v = SqlFormat.HeureFormat(dt, SqlFormat.EFormatDate.DateTime2); AssertAreEqual(v, "'1900-01-01T12:30:00.100'", "Heure? dans datetime2 23/10/2000 12h30:00.100"); v = SqlFormat.HeureFormat(new DateTime(2000, 10, 23, 12, 30, 00, 100), SqlFormat.EFormatDate.DateTime2, true); AssertAreEqual(v, "'1900-01-01T12:30:00.100'", "Heure? dans datetime2 nullable 23/10/2000 12h30:00.100"); // Heure dans time dt = null; v = SqlFormat.HeureFormat(dt, SqlFormat.EFormatDate.Time); AssertAreEqual(v, "NULL", "Heure? dans time Null"); dt = new DateTime(2000, 10, 23, 12, 30, 00, 100); v = SqlFormat.HeureFormat(dt, SqlFormat.EFormatDate.Time); AssertAreEqual(v, "'12:30:00.100'", "Heure? dans time 12h30:00.100"); v = SqlFormat.HeureFormat(new DateTime(2000, 10, 23, 12, 30, 00, 100), SqlFormat.EFormatDate.Time, true); AssertAreEqual(v, "'12:30:00.100'", "Heure? dans time nullable 23/10/2000 12h30:00.100"); // mise à jour de la date pivot SqlFormat.DatePivotHeure = new DateTime(1753, 1, 1); pivot = SqlFormat.DatePivotHeure; AssertAreEqual(pivot, new DateTime(1753, 1, 1), "Date pivot non modifiée"); dt = new DateTime(2000, 10, 23, 12, 30, 00, 100); v = SqlFormat.HeureFormat(dt); AssertAreEqual(v, "'1753-01-01T12:30:00'", "Heure? dans datetime 23/10/2000 12h30:00.100"); SqlFormat.RestaureDatePivot(); pivot = SqlFormat.DatePivotHeure; AssertAreEqual(pivot, new DateTime(1900, 1, 1), "Date pivot non restaurée"); }