[SetUp] public void SetUp() { parseDate = new ParseDate { Processor = new CellProcessorBase() }; exceptionMessage = string.Empty; }
public void CheckRequired() { var tag = new ParseDate(); RequiredAttribute.Check(tag); //no exceptions }
[SetUp] public void SetUp() { parseDate = new ParseDate { Processor = Builder.CellProcessor() }; exceptionMessage = string.Empty; }
public void ParseDate_GetJson_UtcInput_CorrectJson() { var parseDate = new ParseDate(new DateTime(2013, 1, 2, 14, 3, 4, 5, DateTimeKind.Utc)); string resultJson = JsonConvert.SerializeObject(parseDate); Assert.That(resultJson, Is.EqualTo("{\"__type\":\"Date\",\"iso\":\"2013-01-02T14:03:04.005Z\"}")); }
public void ParseDate_UtcTime_JsonInput_UtcNotLocal() { string json = "{\"__type\":\"Date\",\"iso\":\"2013-01-02T14:03:04.005Z\"}"; ParseDate parseDate = JsonConvert.DeserializeObject <ParseDate>(json); Assert.That(parseDate.UtcTime, Is.EqualTo(new DateTime(2013, 1, 2, 14, 3, 4, 5, DateTimeKind.Utc))); }
public void TestSimpleFormatOfEmptyString() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("")); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); }
public void TestSimpleParse() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("1/6/2008 12:00 AM")); date.Var = new MockAttribute(new Constant("result")); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2008, 1, 6, 0, 0, 0))); }
public void TestSimpleFormatOfWithCustomPattern() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("03 Feb 2001T04:05")); date.Var = new MockAttribute(new Constant("result")); date.Pattern = new MockAttribute(new Constant("dd MMM yyyy'T'HH:mm")); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2001, 2, 3, 4, 5, 0))); }
public void ParseDate_Equals_DifferentObjects_ReturnsFalse() { var date1 = new ParseDate(new DateTime(2013, 1, 2, 14, 3, 4, 5, DateTimeKind.Utc)); // Only off by 1 second, but should return false. var date2 = new ParseDate(new DateTime(2013, 1, 2, 14, 3, 4, 6, DateTimeKind.Utc)); bool result = date1.Equals(date2); Assert.That(result, Is.False); }
public void TestSimpleFormatOfDateTimeExplicitBoth() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("1/6/2008 04:13 AM")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Both.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2008, 1, 6, 4, 13, 0))); }
public void TestSimpleFormatOfWithBothLongFormat() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("Saturday, February 03, 2001 4:05:06 AM")); date.TimeStyle = new MockAttribute(new Constant(TimeStyle.Long.ToString())); date.DateStyle = new MockAttribute(new Constant(DateStyle.Long.ToString())); date.Var = new MockAttribute(new Constant("result")); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2001, 2, 3, 4, 5, 6))); }
public void ParseDate_Equals_SameValues_ReturnsTue() { var date1 = new ParseDate(new DateTime(2013, 1, 2, 14, 3, 4, 5, DateTimeKind.Utc)); var date2 = new ParseDate(DateTime.Now); date2.UtcTime = new DateTime(2013, 1, 2, 14, 3, 4, 5, DateTimeKind.Utc); bool result = date1.Equals(date2); Assert.That(result, Is.True); }
public void TestSimpleFormatOfDifferentDateStyle_ExplicitDefault() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("1/6/2008")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Date.ToString())); date.DateStyle = new MockAttribute(new Constant(DateStyle.Default.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2008, 1, 6, 0, 0, 0))); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var obj = JObject.Load(reader); var ret = new ParseDate { Value = obj.Value <DateTime>("iso") }; return(ret); }
public void TestSimpleFormatOfDifferentDateStyle_Long() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("Saturday, February 03, 2001")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Date.ToString())); date.DateStyle = new MockAttribute(new Constant(DateStyle.Long.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2001, 2, 3, 0, 0, 0))); }
public void TestSimpleFormatOfDateTimeOnlyDate() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("1/6/2008")); date.Exact = new MockAttribute(new Constant("true")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Date.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2008, 1, 6, 0, 0, 0))); }
public void TestSimpleFormatOfDateTimeOnlyTime() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("4:12 AM")); date.Exact = new MockAttribute(new Constant("true")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Time.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 4, 12, 0))); }
private IEnumerable <DateTime> GetDatesInWeek(IReadOnlyList <HtmlNode> cols, int year) { const int OFFSET = 1; for (var day = OFFSET; day < NUMBER_OF_WORKDAYS + OFFSET; day++) { var divs = cols[day].Descendants().Where(x => x.IsDiv()).ToList(); var dateString = divs[0].InnerText.Trim(); DateTime dateWithoutTime = ParseDate.StringToDateTime(dateString, year); yield return(dateWithoutTime); } }
public void TestSimpleFormatOfDifferentDateStyle_ShortDifferentCulture() { _model.Page[FormatConstants.LOCALE] = new CultureInfo("nl-NL"); var date = new ParseDate(); date.Value = new MockAttribute(new Constant("6-1-2008")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Date.ToString())); date.DateStyle = new MockAttribute(new Constant(DateStyle.Default.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(2008, 1, 6, 0, 0, 0))); }
public void TestSimpleFormatOfDifferentTimeStyle_Long() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("4:05:06 AM")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Time.ToString())); date.TimeStyle = new MockAttribute(new Constant(TimeStyle.Long.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 4, 5, 6))); }
public void TestSimpleFormatOfDifferentTimeStyle_ShortDifferentCulture() { _model.Page[FormatConstants.LOCALE] = new CultureInfo("nl-NL"); var date = new ParseDate(); date.Value = new MockAttribute(new Constant("16:12")); date.Var = new MockAttribute(new Constant("result")); date.Type = new MockAttribute(new Constant(DateType.Time.ToString())); date.TimeStyle = new MockAttribute(new Constant(TimeStyle.Default.ToString())); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); Assert.That(_model.Page["result"], Is.EqualTo(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 16, 12, 0))); }
private IEnumerable <ScheduleItem> ExtractScheduleItemFromSingleItem(HtmlNode dayRowColumn, DateTime date, string location) { if (!dayRowColumn.HasChildNodes) { yield break; } if (dayRowColumn.ChildNodes.Count(x => x.IsElement()) < 2) { yield break; } IEnumerable <HtmlNode> locationSchedules = dayRowColumn.ChildNodes.Where(x => x.IsTable() && x.ClassContains("locatieplanning_2colommen")); foreach (HtmlNode locationSchedule in locationSchedules) { if (!locationSchedule.IsTable() || !locationSchedule.ClassContains("locatieplanning_2colommen")) { // strange behavior.// check continue; } HtmlNode[] elementRows = locationSchedule.ChildNodes.Where(x => x.IsElement()).ToArray(); if (elementRows.Length is < 2 or > 3) { continue; } HtmlNode dataRow = elementRows[1]; if (dataRow.ChildNodes.Count(x => x.IsElement()) != 2) { continue; } HtmlNode tdStartEndTime = dataRow.ChildNodes.First(x => x.IsElement()); // <td class="left">09:00-18:30</td> var times = tdStartEndTime.InnerText.Trim(); // i.e. 09:00-18:00 (DateTime start, DateTime end) = ParseDate.CreateStartEndDateTimeTuple(date, times); yield return(new ScheduleItem { Start = start, End = end, Location = location, }); } }
public void TestSimpleParse_ExplicitExact_WrongFormat() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("1/6/2008 12:00:00")); date.Exact = new MockAttribute(new Constant("true")); try { date.Evaluate(_model); Assert.Fail("Should fail"); } catch (TagException Te) { Assert.That(Te.Message, Is.EqualTo(TagException.ParseException("1/6/2008 12:00:00", "Date").Message)); } }
public void TestSimpleFormatOfWithCustomPatternWithTimeZone() { var date = new ParseDate(); date.Value = new MockAttribute(new Constant("04:05 +02:00")); date.Pattern = new MockAttribute(new Constant("HH:mm zzz")); date.Var = new MockAttribute(new Constant("result")); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 3, 5, 0); if (dt.IsDaylightSavingTime()) { dt = dt.AddHours(1); } Assert.That(((DateTime)_model.Page["result"]), Is.EqualTo(dt)); }
public void TestSimpleFormatOfDifferentDateStyle_Wrong() { var date = new ParseDate(); _model.Model["DateValue"] = new DateTime(2001, 2, 3, 4, 5, 6); date.Value = new MockAttribute(new Property("DateValue")); date.Type = new MockAttribute(new Constant(DateType.Date.ToString())); date.DateStyle = new MockAttribute(new Constant("Wrong")); try { date.Evaluate(_model); Assert.Fail("Expected failure"); } catch (ArgumentException Ae) { Assert.That(Ae.Message.Contains("Wrong")); } }
public static void AddParseBody(this HttpWebRequest request, ParseObject body) { var dict = new Dictionary <string, object>(); foreach (var prop in body.GetType().GetProperties()) { var value = prop.GetValue(body, null); if (prop.PropertyType == typeof(DateTime)) { value = new ParseDate((DateTime)value); } else if (prop.PropertyType == typeof(byte[])) { value = new ParseBytes((byte[])value); } else if (typeof(ParseObject).IsAssignableFrom(prop.PropertyType)) { if (value != null) { value = new ParsePointer((ParseObject)value); } } else if (prop.PropertyType.IsGenericType && value is IList && typeof(ParseObject).IsAssignableFrom(prop.PropertyType.GetGenericArguments()[0])) { // explicity skip relations, need to be dealt with manually continue; // var pointers = ((IList) value).Cast<ParseObject>().Select(x => new ParsePointer(x)).ToList(); // value = pointers.Count == 0 ? null : new {__op = "AddRelation", objects = pointers}; } var attrs = prop.GetCustomAttributes(true); JsonIgnoreForSerializationAttribute jsonIgnore = null; JsonPropertyAttribute jsonProp = null; foreach (var attr in attrs) { var tmp1 = attr as JsonPropertyAttribute; if (tmp1 != null) { jsonProp = tmp1; } var tmp2 = attr as JsonIgnoreForSerializationAttribute; if (tmp2 != null) { jsonIgnore = tmp2; } } if (jsonIgnore != null) { continue; } if (jsonProp != null && !string.IsNullOrEmpty(jsonProp.PropertyName)) { dict[jsonProp.PropertyName] = value; } else { dict[prop.Name] = value; } } request.AddBody(dict); }
public static DateTime ToProvinciaDateTime(this string str) { var parse = new ParseDate(str); return(parse.GetDateBancoProvincia()); }
[SetUp] public void SetUp() { parseDate = new ParseDate {Processor = Builder.CellProcessor()}; exceptionMessage = string.Empty; }
public void SetUp() { parseDate = new ParseDate {Processor = new CellProcessorBase()}; exceptionMessage = string.Empty; }
// private async Task<HtmlAgilityPack.HtmlDocument> GetDocument(HttpResponseMessage responseMessage) // { //// string result = await responseMessage.Content.ReadAsStringAsync(); //// if (!responseMessage.IsSuccessStatusCode) //// throw new FileNotFoundException("Unable to retrieve document"); // } public List <ScheduleItem> GetScheduleFromContent() { var result = new List <ScheduleItem>(); var divsIdUrenregistratie = Document.DocumentNode.Descendants() .Where(x => (x.IsDiv() && x.IdEquals("urenregistratie"))) .ToList(); if (divsIdUrenregistratie.Count() != 1) { Logger.Error("urenregistratieDiv"); return(null); } var divIdUrenregistratie = divsIdUrenregistratie.First(); var tablesIdLocatieWeekoverzicht = divIdUrenregistratie.Descendants() .Where(x => x.IdEquals("locatie_weekoverzicht")) .ToList(); if (tablesIdLocatieWeekoverzicht.Count() != 1) { Logger.Error("tableLocaties"); return(null); } var tableIdLocatieWeekoverzicht = tablesIdLocatieWeekoverzicht.First(); // get head (hierin zitten de dagen en de datums) var theads = tableIdLocatieWeekoverzicht.Descendants().Where(x => x.IsThead()).ToList(); if (theads.Count() != 1) { Logger.Error("theads"); return(null); } var thead = theads.First(); //get tr var rows = thead.Descendants().Where(x => x.IsTr()).ToList(); if (rows.Count() != 1) { Logger.Error("rows"); return(null); } var row = rows.First(); //get columns var cols = row.Descendants().Where(x => x.IsTh()).ToList(); if (cols.Count() != 5 + 1) //5 days + first column is info { Logger.Error("cols"); return(null); } // first column is nothing.. // second till 6th is monday till friday // var colMa = cols[1]; // var colDi = cols[2]; // var colWo = cols[3]; // var colDo = cols[4]; // var colVr = cols[5]; // for (int i = 1; i < 6; i++) // { // divs = cols[i].Descendants().Where(x => x.IsDiv()).ToList(); // if (divs.Count() == 2) // { // Console.WriteLine("--------------------"); // Console.WriteLine(divs[0].InnerText.Trim()); //day/date // Console.WriteLine(divs[1].InnerText.Trim()); //total hours to work that day // Console.WriteLine("--------------------"); // } // } // var tbodys = tableIdLocatieWeekoverzicht.Descendants().Where(x => x.Name == "tbody").ToList(); var tbodys = tableIdLocatieWeekoverzicht.ChildNodes.Where(x => x.IsTbody()).ToList(); var tbody = tbodys.First(); var trs2 = tbody.ChildNodes.Where(x => x.IsTr()).ToList(); foreach (var tr in trs2) { //get columns var tds = tr.ChildNodes.Where(x => x.IsTd()).ToList(); // first column is info var infoTd = tds.First(); // deze heeft 4 divs var infoTdDivs = infoTd.ChildNodes.Where(x => x.IsDiv()).ToList(); // for (int i = 0; i < infoTdDivs.Count; i++) // { // Console.WriteLine(infoTdDivs[i].Attributes.First().Value); // Console.WriteLine(infoTdDivs[i].InnerText); // Console.WriteLine("+++++++++++++++++++++"); // } // second till 6th is monday till friday // var colMa = cols[1]; // var colDi = cols[2]; // var colWo = cols[3]; // var colDo = cols[4]; // var colVr = cols[5]; //dagen for (int i = 1; i < 6; i++) { if (tds[i].HasChildNodes) { // at least one locatieplanning_2colommen en 1 div met totaal // kunnen meerdere locatieplanning_2collomen zijn if (tds[i].ChildNodes.Count(x => x.IsElement()) >= 2) { var locatieplanningen = tds[i].ChildNodes.Where(x => x.IsTable() && x.ClassContains("locatieplanning_2colommen")); foreach (var firstItem in locatieplanningen) { //table //var firstItem = tds[i].ChildNodes.First(x => x.IsElement()); //firstItem.Class() = ""; if (firstItem.IsTable() && firstItem.ClassContains("locatieplanning_2colommen")) { /* * <table class="locatieplanning_2colommen dienst" width="100%"> * <tr> * <td class="locatieplanning_naam bold" colspan=2> * Dienst * </td> * </tr> * <tr> * <td class="left">09:00-18:30</td> * <td class="right">(09:00)</td> * </tr> * </table> */ if (firstItem.ChildNodes.Count(x => x.IsElement()) == 2) { var firstRow = firstItem.ChildNodes.First(x => x.IsElement()); var lastRow = firstItem.ChildNodes.Last(x => x.IsElement()); if (lastRow.ChildNodes.Count(x => x.IsElement()) == 2) { var firstTd = lastRow.ChildNodes.First(x => x.IsElement()); //<td class="left">09:00-18:30</td> var lastTd = lastRow.ChildNodes.Last(x => x.IsElement()); //<td class="right">(09:00)</td> var times = firstTd.InnerText.Trim(); //ie. 09:00-18:00 var divs = cols[i].Descendants().Where(x => x.IsDiv()).ToList(); var dateString = divs[0].InnerText.Trim(); var locationString = infoTdDivs[3].InnerText; var dateWithoutTime = ParseDate.StringToDateTime(dateString, year); var startEndDateTimeTuple = ParseDate.CreateStartEndDateTimeTuple(dateWithoutTime, times); result.Add(new ScheduleItem() { Start = startEndDateTimeTuple.Item1, End = startEndDateTimeTuple.Item2, Location = locationString }); } } } } } // var divs2 = tds[i].Descendants().Where(x => x.IsDiv()).ToList(); // if (divs2.Count() == 2) // { // Console.WriteLine("--------------------"); // Console.WriteLine(divs2[0].InnerText.Trim()); // Console.WriteLine(divs2[1].InnerText.Trim()); // Console.WriteLine("--------------------"); // } } } } return(result); }
public void TestEmpty() { var date = new ParseDate(); Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty)); }