public static JwTime CreateTime(int hh, int mm, int ss, int ms) { JwTime t; t = new JwTime(); t.Set(hh, mm, ss, ms); return t; }
//# __________ PROTOCOL :: FORMAT __________ #// /** * I provide a very simple, and non-optimized, facility for formatting * dates in a variety of formats. Valid format codes are: * {H} : hour (1-12) * {HH} : hour (01-12) * {H24} : hour (0-23) * {HH24} : hour (00-23) * {M} : minute (0-59) * {MM} : minute (00-59) * {S} : second (0-59) * {SS} : second (00-59) * {MS} : millisecond (000-999) * {am/pm}: am/pm (am, pm) */ public static String Format(JwTime e, String format) { if ( e == null ) return null; String s = format; s = JwUtility.ReplaceAll(s, "{H}", e.GetHour12()+""); s = JwUtility.ReplaceAll(s, "{HH}", Pad2(e.GetHour12())); s = JwUtility.ReplaceAll(s, "{H24}", e.GetHour()+""); s = JwUtility.ReplaceAll(s, "{HH24}", Pad2(e.GetHour())); s = JwUtility.ReplaceAll(s, "{M}", e.GetMinute()+""); s = JwUtility.ReplaceAll(s, "{MM}", Pad2(e.GetMinute())); s = JwUtility.ReplaceAll(s, "{S}", e.GetSecond()+""); s = JwUtility.ReplaceAll(s, "{SS}", Pad2(e.GetSecond())); s = JwUtility.ReplaceAll(s, "{MS}", Pad3(e.GetMillisecond())); s = JwUtility.ReplaceAll(s, "{/p}", e.IsAm() ? "" : "p"); s = JwUtility.ReplaceAll(s, "{/pm}", e.IsAm() ? "" : "pm"); s = JwUtility.ReplaceAll(s, "{a/p}", e.IsAm() ? "a" : "p"); s = JwUtility.ReplaceAll(s, "{A/P}", e.IsAm() ? "A" : "P"); s = JwUtility.ReplaceAll(s, "{am/pm}", e.IsAm() ? "am" : "pm"); s = JwUtility.ReplaceAll(s, "{AM/PM}", e.IsAm() ? "AM" : "PM"); return s; }
public static JwTime CreateNowUtc() { JwTime t; t = new JwTime(); t.SetNowUtc(); return t; }
public static JwTime CreateTime(DateTime dt) { // kludge (err) - need to learn how to check DateTime for empty //if ( dt == null ) return null; JwTime t = new JwTime(); t.Set(dt); return t; }
//# __________ PROTOCOL :: INSTANCE CREATION __________ #// public static JwTimestamp CreateTimestamp(JwDate d, JwTime t) { JwTimestamp ts; ts = new JwTimestamp(); ts.SetDate(d); ts.SetTime(t); return ts; }
//# __________ PROTOCOL :: INSTANCE CREATION __________ #// public static JwTimeInterval CreateTimeInterval(JwTime start, JwTime end) { JwTimeInterval ti; ti = new JwTimeInterval(); ti.SetStart(start); ti.SetEnd(end); return ti; }
//# __________ PROTOCOL :: FORMAT __________ #// public static String Format_h_mm_am(JwTime t) { if ( t == null ) return null; int hh = t.GetHour(); int mm = t.GetMinute(); String suffix = AM; if ( t.IsPm() ) { hh -= 12; suffix = PM; } if ( hh == 0 ) hh = 12; return hh + COLON + Pad2(mm) + suffix; }
//# __________ PROTOCOL :: COPY __________ #// public JwTime GetTimeCopy() { JwTime e; e = new JwTime(); e.SetOrdinal(_ordinal); return e; }
public JwDuration Difference(JwTime t) { long a = GetOrdinal(); long b = t.GetOrdinal(); long c = Math.Abs(a-b); JwDuration e = new JwDuration(); e.SetOrdinal(c); return e; }
public void SetEnd(JwTime t) { _end = t; }
public bool IsOnOrBefore(JwTime d) { return CompareTo(d) <= 0; }
/** * Determine if I am between the start and end time, also return true * if I am equal to either the start or end time. */ public bool IsBetweenInclusive(JwTime start, JwTime end) { if ( start != null && IsBefore(start) ) return false; if ( end != null && IsAfter(end) ) return false; return true; }
public String format(JwTime t) { return _formatter.Format(t); }
//# __________ PROTOCOL :: CONSTRUCTOR __________ #// public JwTimestamp() { _date = new JwDate(); _time = new JwTime(); }
public void SetTime(JwTime e) { _time = e; }
/** * Determine if this interval contains the time. The test excludes * the start and end dates. */ public bool ContainsExclusive(JwTime t) { if ( t == null ) return false; if ( HasStart() && GetStart().IsOnOrAfter(t) ) return false; if ( HasEnd() && GetEnd().IsOnOrBefore(t) ) return false; return true; }
//# __________ PROTOCOL :: INTERSECTION __________ #// /** * @see containsInclusive */ public bool Contains(JwTime t) { return ContainsInclusive(t); }
public bool IsAfter(JwTime d) { return CompareTo(d) > 0; }
public void SetStart(JwTime t) { _start = t; }
//# __________ PROTOCOL :: COMPARE (convenience) __________ #// public bool IsBefore(JwTime d) { return CompareTo(d) < 0; }
//# __________ PROTOCOL :: STATIC __________ #// public static String FormatTime(JwTime time, String format) { JwTimeFormatter tf = new JwTimeFormatter(format); return tf.Format(time); }
public bool IsOnOrAfter(JwTime d) { return CompareTo(d) >= 0; }
public bool HasStart(JwTime t) { return JwUtility.IsEqual(GetStart(), t); }
public String formatHoursAndMinutes(JwTime t) { return _shortFormatter.Format(t); }
//# __________ PROTOCOL :: CONTRUCTOR __________ #// public JwTimeInterval() { _start = null; _end = null; }
public static String Format_h_mm_ss_msss(JwTime t) { if ( t == null ) return null; int hh = t.GetHour(); int mm = t.GetMinute(); int ss = t.GetSecond(); int ms = t.GetMillisecond(); return hh + COLON + Pad2(mm) + COLON + Pad2(ss) + DOT + Pad3(ms); }
public static String Format_h_mm_ss_msss_am(JwTime t) { if ( t == null ) return null; int hh = t.GetHour(); int mm = t.GetMinute(); int ss = t.GetSecond(); int ms = t.GetMillisecond(); String suffix = AM; if ( t.IsPm() ) { hh -= 12; suffix = PM; } if ( hh == 0 ) hh = 12; return hh + COLON + Pad2(mm) + COLON + Pad2(ss) + DOT + Pad3(ms) + suffix; }
//# __________ PROTOCOL :: FORMAT __________ #// public String Format(JwTime e) { return JwTimeUtility.Format(e, _format); }
public bool HasEnd(JwTime t) { return JwUtility.IsEqual(GetEnd(), t); }