public period(string str) { str = str.ToUpper(); length_ = int.Parse(str.Substring(0, str.Length - 1)); string freq = str.Substring(str.Length - 1, 1); switch (freq) { case "D": unit_ = timeUnit.days; break; case "W": unit_ = timeUnit.weeks; break; case "M": unit_ = timeUnit.months; break; case "Q": unit_ = timeUnit.quarters; break; case "Y": unit_ = timeUnit.years; break; default: throw new ArgumentException("Unknown TimeUnit: " + freq); } }
public void convertTo(timeUnit to) { while (units > to) { --units; Console.WriteLine("here"); magnitude *= 60; } while (units < to) { ++units; Console.WriteLine("there"); magnitude /= 60; } }
public void normalize() { if (length_ != 0) { switch (unit_) { case timeUnit.days: if ((length_ % 7) == 0) { length_ /= 7; unit_ = timeUnit.weeks; } break; case timeUnit.months: if ((length_ % 12) == 0) { length_ /= 12; unit_ = timeUnit.years; } else if ((length_ % 3) == 0) { length_ /= 3; unit_ = timeUnit.quarters; } break; case timeUnit.quarters: if ((length_ % 4) == 0) { length_ /= 4; unit_ = timeUnit.years; } break; case timeUnit.weeks: case timeUnit.years: break; default: throw new ArgumentException("Unknown TimeUnit: " + unit_); } } }
public string getTime(timeUnit Unit) { long timeSeconds = timer.ElapsedMilliseconds / Convert.ToInt32(Unit); return(timeSeconds.ToString()); }
public Time(double mag, timeUnit unit) { Magnitude = mag; units = unit; }
public period() { length_ = 0; unit_ = timeUnit.days; }
// ctors public period(int length, timeUnit unit) { length_ = length; unit_ = unit; }
public static period operator +(period p1, period p2) { int length_ = p1.length; timeUnit units_ = p1.unit; if (length_ == 0) { length_ = p2.length; units_ = p2.unit; } else if (units_ == p2.unit) { // no conversion needed length_ += p2.length; } else { switch (units_) { case timeUnit.years: switch (p2.unit) { case timeUnit.months: units_ = timeUnit.months; length_ = length_ * 12 + p2.length; break; case timeUnit.quarters: units_ = timeUnit.quarters; length_ = length_ * 4 + p2.length; break; case timeUnit.weeks: case timeUnit.days: if (p1.length != 0) { throw new Exception( "impossible addition between " + p1 + " and " + p2); } break; default: throw new Exception("unknown time unit (" + p2.unit + ")"); } break; case timeUnit.quarters: switch (p2.unit) { case timeUnit.years: length_ += p2.length * 4; break; case timeUnit.months: length_ += p2.length * 4; break; case timeUnit.weeks: case timeUnit.days: if (p1.length != 0) { throw new Exception( "impossible addition between " + p1 + " and " + p2); } break; default: throw new Exception("unknown time unit (" + p2.unit + ")"); } break; case timeUnit.months: switch (p2.unit) { case timeUnit.years: length_ += p2.length * 12; break; case timeUnit.weeks: case timeUnit.days: if (p1.length != 0) { throw new Exception( "impossible addition between " + p1 + " and " + p2); } break; default: throw new Exception("unknown time unit (" + p2.unit + ")"); } break; case timeUnit.weeks: switch (p2.unit) { case timeUnit.days: units_ = timeUnit.days; length_ = length_ * 7 + p2.length; break; case timeUnit.years: case timeUnit.months: if (p1.length != 0) { throw new Exception( "impossible addition between " + p1 + " and " + p2); } break; default: throw new Exception("unknown time unit (" + p2.unit + ")"); } break; case timeUnit.days: switch (p2.unit) { case timeUnit.weeks: length_ += p2.length * 7; break; case timeUnit.years: case timeUnit.months: if (p1.length != 0) { throw new Exception( "impossible addition between " + p1 + " and " + p2); } break; default: throw new Exception("unknown time unit (" + p2.unit + ")"); } break; default: throw new Exception("unknown time unit (" + units_ + ")"); } } return(new period(length_, units_)); }