/// <summary> /// Given a numeric value, converts the value and unit to a TimeSpan. /// </summary> /// <param name="unit">Unit of the value.</param> /// <param name="value">Value to convert.</param> /// <returns>Converted TimeSpan value.</returns> public static TimeSpan ToTimeSpan(this TimeUnitEnum unit, double value) { switch (unit) { case TimeUnitEnum.Second: return(TimeSpan.FromSeconds(value)); case TimeUnitEnum.Minute: return(TimeSpan.FromMinutes(value)); case TimeUnitEnum.Hour: return(TimeSpan.FromHours(value)); case TimeUnitEnum.Day: return(TimeSpan.FromDays(value)); case TimeUnitEnum.Month: return(TimeSpan.FromDays(value / 30.0)); case TimeUnitEnum.Year: return(TimeSpan.FromDays(value / 365.25)); default: throw new ArgumentException( string.Format("Unknown unit: {0}.", unit)); } }
public bool ReplaceTask(int taskId, Action callBack, float delay, TimeUnitEnum timeUnitEnum = TimeUnitEnum.Millisecond, int count = 1) { if (timeUnitEnum != TimeUnitEnum.Millisecond) { switch (timeUnitEnum) { case TimeUnitEnum.Second: delay = delay * 1000; break; case TimeUnitEnum.Minute: delay = delay * 1000 * 60; break; case TimeUnitEnum.Hour: delay = delay * 1000 * 60 * 60; break; case TimeUnitEnum.Day: delay = delay * 1000 * 60 * 60 * 24; break; default: Debug.Log("Add Task TimeUnit Type Error..."); break; } } float destTime = Time.realtimeSinceStartup * 1000 + delay; TimeTask task = new TimeTask(taskId, destTime, callBack, count, delay); bool isRep = false; for (int i = 0; i < taskTimeList.Count; i++) { if (taskTimeList[i].id == taskId) { taskTimeList[i] = task; isRep = true; break; } } if (!isRep) { for (int i = 0; i < tmpTimeList.Count; i++) { if (tmpTimeList[i].id == taskId) { tmpTimeList[i] = task; isRep = true; break; } } } return(isRep); }
/// <summary> /// Initializes a new instance of the <see cref="Period" /> class. /// </summary> /// <param name="_Period">_Period (required).</param> /// <param name="TimeUnit">TimeUnit (required).</param> public Period(int?_Period = default(int?), TimeUnitEnum TimeUnit = default(TimeUnitEnum)) { // to ensure "_Period" is required (not null) if (_Period == null) { throw new InvalidDataException("_Period is a required property for Period and cannot be null"); } else { this._Period = _Period; } // to ensure "TimeUnit" is required (not null) if (TimeUnit == null) { throw new InvalidDataException("TimeUnit is a required property for Period and cannot be null"); } else { this.TimeUnit = TimeUnit; } }
public int AddTimeTask(Action callBack, float delay, TimeUnitEnum timeUnitEnum = TimeUnitEnum.Millisecond, int count = 1) { if (timeUnitEnum != TimeUnitEnum.Millisecond) { switch (timeUnitEnum) { case TimeUnitEnum.Second: delay = delay * 1000; break; case TimeUnitEnum.Minute: delay = delay * 1000 * 60; break; case TimeUnitEnum.Hour: delay = delay * 1000 * 60 * 60; break; case TimeUnitEnum.Day: delay = delay * 1000 * 60 * 60 * 24; break; default: Debug.Log("Add Task TimeUnit Type Error..."); break; } } int id = GetTid(); //realtimesincestartup表示的是从程序开始以来的真实时间 float destTime = Time.realtimeSinceStartup * 1000 + delay; tmpTimeList.Add(new TimeTask(id, destTime, callBack, count, delay)); tidList.Add(id); return(id); }
/// <summary> /// Constructor that accepts values for all mandatory fields /// </summary> ///<param name="units">An Units</param> ///<param name="value">Gets or sets the content value of the &lt;Duration&gt; element</param> /// public Duration(TimeUnitEnum units, int?value) : base(Sif3assessmentDTD.DURATION) { this.SetUnits(units); this.Value = value; }
/// <summary> /// Sets the value of the <c>Units</c> attribute. /// </summary> /// <param name="val">A TimeUnitEnum object</param> /// <remarks> /// <para>Version: 2.6</para> /// <para>Since: 2.6</para> /// </remarks> public void SetUnits(TimeUnitEnum val) { SetField(Sif3assessmentDTD.DURATION_UNITS, val); }
///<summary>Sets the value of the <c><Duration></c> element.</summary> /// <param name="Units">An Units</param> /// <param name="Value">Gets or sets the content value of the &lt;Duration&gt; element</param> ///<remarks> /// <para>This form of <c>setDuration</c> is provided as a convenience method /// that is functionally equivalent to the <c>Duration</c></para> /// <para>Version: 2.6</para> /// <para>Since: 2.6</para> /// </remarks> public void SetDuration(TimeUnitEnum Units, int?Value) { RemoveChild(Sif3assessmentDTD.ACTIVITYTIME_DURATION); AddChild(Sif3assessmentDTD.ACTIVITYTIME_DURATION, new Duration(Units, Value)); }
public static DateTime CalculateExpireDateTime(DateTime startDate, int difference, TimeUnitEnum timeUnit, bool endOfDay = false) { DateTime d; switch (timeUnit) { case TimeUnitEnum.Day: d = startDate.AddDays(difference); break; case TimeUnitEnum.Month: d = startDate.AddMonths(difference); break; case TimeUnitEnum.Year: d = startDate.AddYears(difference); break; default: d = startDate; break; } if (endOfDay) { d = d.Date.AddHours(23).AddMinutes(59).AddSeconds(59); } return d; }
// make a string that describes the schedule static string MakeSchedString(TimeUnitEnum timeUnit, int intervalNum, DateTime startTime, int dayOfWeekMask, int monthOfYearMask, int dayOfMonth, FirstLastEnum firstLast) { string strSchedString = ""; string strFirstLast = ""; string DayString = ""; string[] DayNames = { MainClass.StringTable.GetString("Sunday"), MainClass.StringTable.GetString("Monday"), MainClass.StringTable.GetString("Tuesday"), MainClass.StringTable.GetString("Wednesday"), MainClass.StringTable.GetString("Thursday"), MainClass.StringTable.GetString("Friday"), MainClass.StringTable.GetString("Saturday"), MainClass.StringTable.GetString("day") }; // one time if (timeUnit == TimeUnitEnum.Once) { //strSchedString = startTime.ToString("yyyy/MM/dd HH:mm:ss"); strSchedString = startTime.ToShortDateString() + " " + startTime.ToLongTimeString(); } // daily else if (timeUnit == TimeUnitEnum.Day) { if (intervalNum == 1) { strSchedString = MainClass.StringTable.GetString("DailyAtSpace") + startTime.ToLongTimeString(); } else { strSchedString = MainClass.StringTable.GetString("EverySpace") + intervalNum + MainClass.StringTable.GetString("SpaceDaysAtSpace") + startTime.ToLongTimeString(); } } // weekly else if (timeUnit == TimeUnitEnum.Week) { if (intervalNum == 1) { strSchedString = MainClass.StringTable.GetString("EverySpace") + MakeDayString(dayOfWeekMask, startTime) + MainClass.StringTable.GetString("SpaceAtSpace") + startTime.ToLongTimeString(); } else { strSchedString = MainClass.StringTable.GetString("EverySpace") + intervalNum + MainClass.StringTable.GetString("SpaceWeeksOnSpace") + MakeDayString(dayOfWeekMask, startTime) + MainClass.StringTable.GetString("SpaceAtSpace") + startTime.ToLongTimeString(); } } // monthly else if (timeUnit == TimeUnitEnum.Month) { if (dayOfMonth > 0) { if (monthOfYearMask == (int)MonthMask.AllMonths) { strSchedString = MakeDayNumberString(dayOfMonth) + MainClass.StringTable.GetString("SpaceOfEveryMonthAtSpace") + startTime.ToLongTimeString(); } else { strSchedString = MakeDayNumberString(dayOfMonth) + MainClass.StringTable.GetString("SpaceOfEverySpace") + MakeMonthString(monthOfYearMask) + MainClass.StringTable.GetString("SpaceAtSpace") + startTime.ToLongTimeString(); } } else { if (firstLast == FirstLastEnum.First) { strFirstLast = MainClass.StringTable.GetString("First"); DayString = MakeDayString(dayOfWeekMask, DateTime.MinValue); } else if (firstLast == FirstLastEnum.Second) { strFirstLast = MainClass.StringTable.GetString("Second"); DayString = MakeDayString(dayOfWeekMask, DateTime.MinValue); } else if (firstLast == FirstLastEnum.Third) { strFirstLast = MainClass.StringTable.GetString("Third"); DayString = MakeDayString(dayOfWeekMask, DateTime.MinValue); } else if (firstLast == FirstLastEnum.Fourth) { strFirstLast = MainClass.StringTable.GetString("Fourth"); DayString = MakeDayString(dayOfWeekMask, DateTime.MinValue); } else if (firstLast == FirstLastEnum.Last) { strFirstLast = MainClass.StringTable.GetString("Last"); DayString = MakeDayString(dayOfWeekMask, DateTime.MinValue); } else { string err = "bad firstLast value: " + firstLast; ServiceMessages.InsertRec(MainClass.AppName, "TaskSchedule", "MakeSchedString", err); } if (monthOfYearMask == (int)MonthMask.AllMonths) { strSchedString = strFirstLast + " " + DayString + MainClass.StringTable.GetString("SpaceOfEveryMonthAtSpace") + startTime.ToLongTimeString(); } else { strSchedString = strFirstLast + " " + DayString + MainClass.StringTable.GetString("SpaceOfSpace") + MakeMonthString(monthOfYearMask) + MainClass.StringTable.GetString("SpaceAtSpace") + startTime.ToLongTimeString(); } } } return(strSchedString); }