public static void Examples() { Describe(new TimexProperty("2019-05-29")); Describe(new TimexProperty("XXXX-WXX-6")); Describe(new TimexProperty("XXXX-WXX-6T16")); Describe(new TimexProperty("T12")); Describe(TimexProperty.FromDate(DateTime.Now)); Describe(TimexProperty.FromDate(DateTime.Now + TimeSpan.FromDays(1))); }
public void DataTypes_Creator_nextWeek() { var start = TimexDateHelpers.DateOfNextDay(DayOfWeek.Monday, System.DateTime.Now); var t = TimexProperty.FromDate(start); t.Days = 7; var expected = t.TimexValue; Assert.AreEqual(expected, TimexCreator.NextWeek()); }
private static (object value, string error) Evaluator(Expression expression, IMemory state, Options options) { TimexProperty parsed = null; string result = null; string error = null; var(validYear, validMonth, validDay) = (0, 0, 0); var currentUtcTime = DateTime.UtcNow; var convertedDateTime = currentUtcTime; IReadOnlyList <object> args; (args, error) = FunctionUtils.EvaluateChildren(expression, state, options); if (error == null) { (parsed, error) = FunctionUtils.ParseTimexProperty(args[0]); } if (error == null) { if (parsed.Year != null || parsed.Month == null || parsed.DayOfMonth == null) { error = $"{args[0]} must be a timex string which only contains month and day-of-month, for example: 'XXXX-10-31'."; } } if (error == null) { if (args.Count == 2 && args[1] is string timezone) { object convertedTimeZone = null; (convertedTimeZone, error) = FunctionUtils.ConvertTimeZoneFormat(timezone); if (error == null) { convertedDateTime = TimeZoneInfo.ConvertTimeFromUtc(currentUtcTime, (TimeZoneInfo)convertedTimeZone); } } else { convertedDateTime = currentUtcTime.ToLocalTime(); } } if (error == null) { var(year, month, day) = (convertedDateTime.Year, convertedDateTime.Month, convertedDateTime.Day); if (parsed.Month <= month || (parsed.Month == month && parsed.DayOfMonth < day)) { validYear = year; } else { validYear = year - 1; } validMonth = parsed.Month ?? 0; validDay = parsed.DayOfMonth ?? 0; if (validMonth == 2 && validDay == 29) { while (!DateTime.IsLeapYear(validYear)) { validYear -= 1; } } result = TimexProperty.FromDate(new DateTime(validYear, validMonth, validDay)).TimexValue; } return(result, error); }
public void DataTypes_Timex_FromDate() { Assert.AreEqual("2017-12-05", TimexProperty.FromDate(new System.DateTime(2017, 12, 5)).TimexValue); }