/// <summary> /// Construct a period from a string in ISO 8601 period format /// </summary> /// <param name="period">The ISO 8601 formatted period to parse</param> /// <remarks>This parses a string in the form <c>[dateTime]/[dateTime]</c> or <c>[dateTime]/[duration]</c> /// to create a period. The <c>[dateTime]</c> part(s) should be ISO 8601 formatted date/time values (see /// <see cref="DateUtils.FromISO8601String"/>). The <c>[duration]</c> part should be an ISO 8601 /// formatted duration value (see <see cref="PDI.Duration"/>). The period format is set based on the /// format of the string received.</remarks> /// <exception cref="ArgumentException">This is thrown if the specified period string or any of its parts /// are not valid.</exception> public Period(string period) { if (String.IsNullOrEmpty(period)) { this.StartDateTime = DateTime.MinValue; this.Duration = Duration.Zero; this.Format = PeriodFormat.StartDuration; return; } string[] parts = period.Split('/'); if (parts.Length != 2) { throw new ArgumentException(LR.GetString("ExPeriodInvalidISOFormat"), "period"); } this.StartDateTime = DateUtils.FromISO8601String(parts[0], true); if (!Char.IsDigit(parts[1][0])) { this.Duration = new Duration(parts[1]); this.Format = PeriodFormat.StartDuration; } else { this.EndDateTime = DateUtils.FromISO8601String(parts[1], true); this.Format = PeriodFormat.StartEnd; } }
/// <summary> /// Copy constructor /// </summary> /// <param name="period">The period to copy</param> public Period(Period period) { if (period != null) { this.StartDateTime = period.StartDateTime; this.EndDateTime = period.EndDateTime; this.Format = period.Format; } }
public static bool IsPeriodic(List <int> array, out List <int> begin, out List <int> period) { begin = new List <int>(); period = new List <int>(); if (array == null || array.Count == 0) { return(false); } PeriodFormat pf = new PeriodFormat(array.ToArray()); var AB = pf.GetPeriodStr(); if (AB == null || AB.Count < 2) { return(false); } string A_Str = AB[0]; string[] As = A_Str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var a in As) { begin.Add(int.Parse(a.Trim())); } string[] Bs = AB[1].TrimStart('[').TrimEnd(']').Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (Bs == null || Bs.Length == 0 || Bs[0] == string.Empty) { return(false); } foreach (var b in Bs) { period.Add(int.Parse(b.Trim())); } return(true); }
/// <summary> /// Construct a period from a start date and an end date /// </summary> /// <param name="startDateTime">The start date/time of the period</param> /// <param name="endDateTime">The end date/time of the period</param> /// <remarks>The period format is set to start date with end date</remarks> public Period(DateTime startDateTime, DateTime endDateTime) { this.StartDateTime = startDateTime; this.EndDateTime = endDateTime; this.Format = PeriodFormat.StartEnd; }
/// <summary> /// Construct a period from a start date and a duration /// </summary> /// <param name="startDateTime">The start date/time of the period</param> /// <param name="duration">The duration of the period</param> /// <remarks>The period format is set to start date with duration</remarks> public Period(DateTime startDateTime, Duration duration) { this.StartDateTime = startDateTime; this.Duration = duration; this.Format = PeriodFormat.StartDuration; }
public PeriodItem(PeriodFormat format, Period time) { Display = time.ToString(format); Time = time; }
protected void OnFormatChanged(PeriodFormat oldValue, PeriodFormat newValue) { }
public string ToString(PeriodFormat pformat) { switch (pformat) { case PeriodFormat.Months: return this.Months.ToString(CultureInfo.CurrentCulture); case PeriodFormat.Years: return this.Years.ToString(CultureInfo.CurrentCulture); default: return this.ToString(); } }
/// <summary> /// Construct a period from a string in ISO 8601 period format /// </summary> /// <param name="period">The ISO 8601 formatted period to parse</param> /// <remarks>This parses a string in the form <c>[dateTime]/[dateTime]</c> or <c>[dateTime]/[duration]</c> /// to create a period. The <c>[dateTime]</c> part(s) should be ISO 8601 formatted date/time values (see /// <see cref="DateUtils.FromISO8601String"/>). The <c>[duration]</c> part should be an ISO 8601 /// formatted duration value (see <see cref="PDI.Duration"/>). The period format is set based on the /// format of the string received.</remarks> /// <exception cref="ArgumentException">This is thrown if the specified period string or any of its parts /// are not valid.</exception> public Period(string period) { if(String.IsNullOrEmpty(period)) { this.StartDateTime = DateTime.MinValue; this.Duration = Duration.Zero; this.Format = PeriodFormat.StartDuration; return; } string[] parts = period.Split('/'); if(parts.Length != 2) throw new ArgumentException(LR.GetString("ExPeriodInvalidISOFormat"), "period"); this.StartDateTime = DateUtils.FromISO8601String(parts[0], true); if(!Char.IsDigit(parts[1][0])) { this.Duration = new Duration(parts[1]); this.Format = PeriodFormat.StartDuration; } else { this.EndDateTime = DateUtils.FromISO8601String(parts[1], true); this.Format = PeriodFormat.StartEnd; } }
/// <summary> /// Copy constructor /// </summary> /// <param name="period">The period to copy</param> public Period(Period period) { if(period != null) { this.StartDateTime = period.StartDateTime; this.EndDateTime = period.EndDateTime; this.Format = period.Format; } }
/// <summary> /// Construct a period from a start date and an end date /// </summary> /// <param name="startDateTime">The start date/time of the period</param> /// <param name="endDateTime">The end date/time of the period</param> /// <remarks>The period format is set to start date with end date</remarks> public Period(DateTime startDateTime, DateTime endDateTime) { this.StartDateTime = startDateTime; this.EndDateTime = endDateTime; this.Format = PeriodFormat.StartEnd; }
/// <summary> /// Construct a period from a start date and a duration /// </summary> /// <param name="startDateTime">The start date/time of the period</param> /// <param name="duration">The duration of the period</param> /// <remarks>The period format is set to start date with duration</remarks> public Period(DateTime startDateTime, Duration duration) { this.StartDateTime = startDateTime; this.Duration = duration; this.Format = PeriodFormat.StartDuration; }
protected void OnFormatChanged(PeriodFormat oldValue, PeriodFormat newValue) { }
public PeriodItem(PeriodFormat format, Period time) { Display = time.ToString(format); Time = time; }