/// <summary> /// October 19 2008 /// - changed this to a generic date, so its always a string /// and a generic date class that loads it expecting day/month/year /// and THEN it converts it to a DateTime /// /// /// October 17 /// /// I was getting crashes on other machines with the timeline. /// I assumed that this was because Machine A used DateFormat A /// Machine B used DateFormat B /// And parsing didn't work (the core DateTime.Parse) /// /// I don't know if that is the issue but will try it. /// /// Basically we take the datestring and somehow convert it? /// </summary> /// <param name="sDateString"></param> /// <returns></returns> static public DateTime SafeDateParse(string sDateString) { DateTime newDate = DateTime.Now; newGenericDate genericDate = new newGenericDate(); genericDate.FromString(sDateString); newDate = genericDate.AsDate; return(newDate); /* * try * { * newDate = DateTime.Parse(sDateString); * } * catch (Exception ) * { * // if fails we then try to do an exact parse * try * { * newDate = DateTime.ParseExact(sDateString, "dd-MM-yyyy HH:mm:ss tt", null); * } * catch (Exception ex) * { * Messag eBox.Show(String.Format("SafeDateParse error for {0} with this exception {1}", sDateString, ex.ToString())); * } * } */ }
public holiday(int Icon, string Text, newGenericDate _date, string Caption) { nIcon = Icon; sText = Text; date = _date; sCaption = Caption; }
/// <summary> /// returns the number of days to this specific dates /// </summary> /// <param name="date"></param> /// <returns></returns> public int DaysToStartingDate(newGenericDate date) { int nCount = 0; for (int i = 0; i < date.Month - 1; i++) { nCount += mZoomInPanels[i]; } nCount += date.Day; return(nCount - 1); }
/// <summary> /// October 19 2008 /// - changed this to a generic date, so its always a string /// and a generic date class that loads it expecting day/month/year /// and THEN it converts it to a DateTime /// /// /// October 17 /// /// I was getting crashes on other machines with the timeline. /// I assumed that this was because Machine A used DateFormat A /// Machine B used DateFormat B /// And parsing didn't work (the core DateTime.Parse) /// /// I don't know if that is the issue but will try it. /// /// Basically we take the datestring and somehow convert it? /// </summary> /// <param name="sDateString"></param> /// <returns></returns> public static DateTime SafeDateParse(string sDateString) { DateTime newDate = DateTime.Now; newGenericDate genericDate = new newGenericDate(); genericDate.FromString(sDateString); newDate = genericDate.AsDate; return newDate; /* try { newDate = DateTime.Parse(sDateString); } catch (Exception ) { // if fails we then try to do an exact parse try { newDate = DateTime.ParseExact(sDateString, "dd-MM-yyyy HH:mm:ss tt", null); } catch (Exception ex) { Messag eBox.Show(String.Format("SafeDateParse error for {0} with this exception {1}", sDateString, ex.ToString())); } } */ }
/* /// <summary> * /// called from the appearance class if this is a plot type instead * /// * /// ?: How will dates be stored? * /// </summary> * public void SetToPlotOutline() * { * CalendarType = Appearance.calendertype.Plot; * /* * mZoomOutDetails = new string[]{"Introduction", "Rising Action", "Climax", "Conclusion"}; * mZoomInPanels = new int[]{2, 5, 2, 1}; * mZoomInPanelRules = new int[]{-1,-1,-1,-1}; * mZoomOutWidths = new int[]{3,3,3,3}; * nNumberOfZoomOutPanels = 4; * MonthLabel = "Segment"; * DayLabel = "Moment"; * YearLabel = "None"; * HasYears = false;*/ //} /// <summary> /// adds days to the timeline /// </summary> /// <param name="date"></param> /// <param name="nDays"></param> /// <returns></returns> public newGenericDate AddDays(newGenericDate date, int nDays) { // logic behind adding days // figure out if end of month // : Day > MaxDaysForMonth bool bIsMonthEnd = false; bool bIsYearEnd = false; // set new day date.Day = date.Day + nDays; if (date.Day < 1) { date.Month--; // going back a year if (date.Month < 1) { if (HasYears == true) { date.Month = ZoomOutDetails.Count; date.Year--; } } // error -handling if (date.Month <= 0) { date.Month = 1; date.Day = 1; } else { date.Day = ZoomInPanels[date.Month - 1]; } } if (date.Day > ZoomInPanels[date.Month - 1]) { bIsMonthEnd = true; } if (bIsMonthEnd == true) { // if month++ would exceed number of months // increment months if (date.Month + 1 > ZoomOutDetails.Count) { bIsYearEnd = true; } } if (bIsMonthEnd == true) { date.Day = 1; date.Month++; } if (bIsYearEnd == true) { if (HasYears == true) { date.Month = 1; date.Year++; } else { date.Month = date.Month - 2; // set month back to current month if this type of calendar does not have years date.Day = ZoomInPanels[date.Month - 1]; } } return(date); }