/// <summary> /// This produces a time in Minutes and Seconds, 'unflattend'. /// To convert to a time format, this has to be initialized as a TimeSpan again. /// </summary> /// <param name="time"></param> /// <returns></returns> static public TimeEx ToHMS(TimeSpan time) { TimeEx flat = new TimeEx(); flat.Hours = (time.Days * 24) + time.Hours; flat.Minutes = time.Minutes; flat.Seconds = time.Seconds; return(flat); }
/// <summary> /// This produces a time in Minutes and Seconds, 'unflattend'. /// To convert to a time format, this has to be initialized as a TimeSpan again. /// </summary> /// <param name="time"></param> /// <returns></returns> static public TimeEx ToMS(TimeSpan time) { TimeEx flat = new TimeEx(time); int d = time.Days, h = time.Hours, m = time.Minutes, s = time.Seconds, ms = time.Milliseconds; // flat.Days = 0; flat.Hours = 0; // flat.Minutes = (((d * 24) + (h)) * 60) + m; flat.Seconds = time.Seconds; return(flat); }
public void Reset(string timeBegin, string timeTwo, bool twoIsEnd = true) { TimeBegin = timeBegin; if (twoIsEnd) { TimeEnd = timeTwo; TimeLength = TimeEnd - TimeBegin; } else { TimeLength = timeTwo; TimeEnd = TimeBegin + TimeLength; } }
public void GetFormat(Label linput, TextBox tinput) { string outvalue = null; try { outvalue = GetTimeFormat(tinput.Text).ToString(); } catch { } linput.Text = string.IsNullOrEmpty(outvalue) ? "00:00:00" : outvalue; linput.ForeColor = string.IsNullOrEmpty(outvalue) ? System.Drawing.Color.Red : Label.DefaultForeColor; TimeStruct?ts = TimeEx.GetStruct(tinput.Text); tinput.Text = ts.HasValue ? ts.Value.GetHMS() : "00:00:00"; }
static public TimeEx Parse(string inputString) { if (inputString == null) { return(Empty); } string[] arr = inputString.Split(':'); int count = arr.Length; Array.Clear(arr, 0, arr.Length); Match mc; switch (count) { case 2: mc = rexMST.Match(inputString); break; case 3: mc = rexHMST.Match(inputString); break; case 4: mc = rexDHMST.Match(inputString); break; default: mc = rexST.Match(inputString); break; } TimeEx data = new TimeEx( mc.Groups["dd"].Value == null? "00" : mc.Groups["dd"].Value, mc.Groups["hh"].Value == null? "00" : mc.Groups["hh"].Value, mc.Groups["mm"].Value == null? "00" : mc.Groups["mm"].Value, mc.Groups["ss"].Value == null? "00" : mc.Groups["ss"].Value, mc.Groups["ttt"].Value == null? "00" : mc.Groups["ttt"].Value ); mc = null; return(data); }
static public TimeSpan GetTimeSpan(TimeEx time) { return(TimeSpan.FromSeconds(time.TotalSeconds) /*(time.Hours,time.Minutes,time.Seconds,time.Milliseconds)*/); }
static public double GetTimeFormat(string input) { TimeEx smpte = input; return(smpte.TotalSeconds); }
public string Calculate(TimeFormatString format) { TimeSpan tbegin = TimeBegin; TimeSpan tend = TimeEnd; TimeSpan tlen = TimeEnd - TimeBegin; string sbegin = sempty; string send = sempty; string slen = sempty; TimeEx temp = 0; switch (format) { case TimeFormatString.SECONDS: // temp = TimeEx.ToMS(tbegin); sbegin = string.Format("{0:00}:{1:00}", temp.Minutes, temp.Seconds); // temp = TimeEx.ToMS(tend); send = string.Format("{0:00}:{1:00}", temp.Minutes, temp.Seconds); // temp = TimeEx.ToMS(tlen); slen = string.Format("{0:00}:{1:00}", temp.Minutes, temp.Seconds); // break; case TimeFormatString.MS: // temp = TimeEx.ToMS(tbegin); sbegin = string.Format("{0:00}:{1:00}", temp.Minutes, temp.Seconds); temp = TimeEx.ToMS(tend); send = string.Format("{0:00}:{1:00}", temp.Minutes, temp.Seconds); temp = TimeEx.ToMS(tlen); slen = string.Format("{0:00}:{1:00}", temp.Minutes, temp.Seconds); // break; case TimeFormatString.DHMS: sbegin = string.Format(Strings.TimeOutputFormat_01_DHMS, tbegin); send = string.Format(Strings.TimeOutputFormat_01_DHMS, tend); slen = string.Format(Strings.TimeOutputFormat_01_DHMS, tlen); // break; case TimeFormatString.HMS: temp = TimeEx.ToHMS(tbegin); sbegin = string.Format("{0:00}:{1:00}:{2:00}", temp.Hours, temp.Minutes, temp.Seconds); temp = TimeEx.ToHMS(tend); send = string.Format("{0:00}:{1:00}:{2:00}", temp.Hours, temp.Minutes, temp.Seconds); temp = TimeEx.ToHMS(tlen); slen = string.Format("{0:00}:{1:00}:{2:00}", temp.Hours, temp.Minutes, temp.Seconds); break; case TimeFormatString.HMSF: sbegin = string.Format(Strings.TimeOutputFormat_03_HMSF, tbegin); send = string.Format(Strings.TimeOutputFormat_03_HMSF, tend); slen = string.Format(Strings.TimeOutputFormat_03_HMSF, tlen); break; } //1227:42 return(Strings.Time_Calculation_String .Replace("{time1}", sbegin) .Replace("{time2}", send) .Replace("{difference}", slen) ); }
public TimeCalc Reset(TimeEx t1, TimeEx t2) { this.TimeBegin = t1; this.TimeEnd = t2; return(this); }
public TimeCalc(TimeEx t1, TimeEx t2, TimeFormatString sf = TimeFormatString.HMS) { SelectedFormat = sf; Reset(t1, t2); }