public void DateTime_Test() { using (ObjectExtensions.ConfigScope(new N4pper.ObjectExtensionsConfiguration())) { DateTime now = DateTime.Now; now = now.AddTicks(-(now.Ticks % TimeSpan.FromMilliseconds(1).Ticks)); TestDateTime test = new TestDateTime() { Value = 1, ValueString = "test", ValueDate = now, ValueDateOff = now, ValueDateNull = now, ValueDateOffNull = now }; var props = test.ToPropDictionary(); props["ValueDate"] = ((DateTimeOffset)now).ToUnixTimeMilliseconds(); props["ValueDateOff"] = ((DateTimeOffset)now).ToUnixTimeMilliseconds(); props["ValueDateNull"] = ((DateTimeOffset)now).ToUnixTimeMilliseconds(); props["ValueDateOffNull"] = ((DateTimeOffset)now).ToUnixTimeMilliseconds(); test = test.CopyProperties(props); Assert.Equal(now, test.ValueDate); Assert.Equal(now, test.ValueDateOff); Assert.Equal(now, test.ValueDateNull); Assert.Equal(now, test.ValueDateOffNull); } }
public string ToLongString() { return(string.Format( "Test number: {0}\n" + "Tester ID: {1}\n" + "Trainee ID: {2}\n" + "Date and Time: {3}, {4}:00\n" + "Begin location: {5}\n" + "Passed: {6}\n", TestNumber, TesterID, TraineeID, TestDateTime.ToShortDateString(), TestDateTime.Hour, BeginLocation, testProperties.passed)); }
public void JsonDateTimeConverter() { var date = new DateTime(2022, 6, 21, 1, 2, 3, DateTimeKind.Utc); var obj = new TestDateTime() { Date = date }; var json = JsonSerializer.Serialize(obj); Assert.Equal(@"{""Date"":""2022-06-21T01:02:03Z""}", json); obj = JsonSerializer.Deserialize <TestDateTime>(json); Assert.Equal(date, obj.Date); }
public override string ToString() { string s = "Tester ID: " + TesterID + "\nTrainee ID: " + TraineeID + "\nDate and Time: " + TestDateTime.ToShortDateString() + " " + TestDateTime.Hour + ":00\nCarType: " + Functions.InsertSpacesBeforeUpper(TestingCarType.ToString()) + "\n"; return(s); //string toReturn = string.Format("Test Number: {0},", TestNumber); //toReturn += string.Format("Tester ID: {0},", TesterID); //toReturn += string.Format("Trainee ID: {0},", TraineeID); //toReturn += string.Format("Date and Time: {0}, {1}:00", TestDateTime.ToShortDateString(), TestDateTime.Hour); //return toReturn; }