Beispiel #1
0
 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;
 }
Beispiel #2
0
        //# __________ 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;
        }
Beispiel #3
0
 public static JwTime CreateNowUtc()
 {
     JwTime t;
     t = new JwTime();
     t.SetNowUtc();
     return t;
 }
Beispiel #4
0
 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;
 }
Beispiel #5
0
 //# __________ PROTOCOL :: INSTANCE CREATION __________ #//
 public static JwTimestamp CreateTimestamp(JwDate d, JwTime t)
 {
     JwTimestamp ts;
     ts = new JwTimestamp();
     ts.SetDate(d);
     ts.SetTime(t);
     return ts;
 }
Beispiel #6
0
 //# __________ PROTOCOL :: INSTANCE CREATION __________ #//
 public static JwTimeInterval CreateTimeInterval(JwTime start, JwTime end)
 {
     JwTimeInterval ti;
     ti = new JwTimeInterval();
     ti.SetStart(start);
     ti.SetEnd(end);
     return ti;
 }
Beispiel #7
0
        //# __________ 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;
        }
Beispiel #8
0
 //# __________ PROTOCOL :: COPY __________ #//
 public JwTime GetTimeCopy()
 {
     JwTime e;
     e = new JwTime();
     e.SetOrdinal(_ordinal);
     return e;
 }
Beispiel #9
0
 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;
 }
Beispiel #10
0
 public void SetEnd(JwTime t)
 {
     _end = t;
 }
Beispiel #11
0
 public bool IsOnOrBefore(JwTime d)
 {
     return CompareTo(d) <= 0;
 }
Beispiel #12
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;
 }
Beispiel #13
0
 public String format(JwTime t)
 {
     return _formatter.Format(t);
 }
Beispiel #14
0
 //# __________ PROTOCOL :: CONSTRUCTOR __________ #//
 public JwTimestamp()
 {
     _date = new JwDate();
     _time = new JwTime();
 }
Beispiel #15
0
 public void SetTime(JwTime e)
 {
     _time = e;
 }
Beispiel #16
0
 /**
  * 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;
 }
Beispiel #17
0
 //# __________ PROTOCOL :: INTERSECTION __________ #//
 /**
  * @see containsInclusive
  */
 public bool Contains(JwTime t)
 {
     return ContainsInclusive(t);
 }
Beispiel #18
0
 public bool IsAfter(JwTime d)
 {
     return CompareTo(d) > 0;
 }
Beispiel #19
0
 public void SetStart(JwTime t)
 {
     _start = t;
 }
Beispiel #20
0
 //# __________ PROTOCOL :: COMPARE (convenience) __________ #//
 public bool IsBefore(JwTime d)
 {
     return CompareTo(d) < 0;
 }
Beispiel #21
0
 //# __________ PROTOCOL :: STATIC __________ #//
 public static String FormatTime(JwTime time, String format)
 {
     JwTimeFormatter tf = new JwTimeFormatter(format);
     return tf.Format(time);
 }
Beispiel #22
0
 public bool IsOnOrAfter(JwTime d)
 {
     return CompareTo(d) >= 0;
 }
Beispiel #23
0
 public bool HasStart(JwTime t)
 {
     return JwUtility.IsEqual(GetStart(), t);
 }
Beispiel #24
0
 public String formatHoursAndMinutes(JwTime t)
 {
     return _shortFormatter.Format(t);
 }
Beispiel #25
0
 //# __________ PROTOCOL :: CONTRUCTOR __________ #//
 public JwTimeInterval()
 {
     _start = null;
     _end = null;
 }
Beispiel #26
0
        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);
        }
Beispiel #27
0
        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;
        }
Beispiel #28
0
 //# __________ PROTOCOL :: FORMAT __________ #//
 public String Format(JwTime e)
 {
     return JwTimeUtility.Format(e, _format);
 }
Beispiel #29
0
 public bool HasEnd(JwTime t)
 {
     return JwUtility.IsEqual(GetEnd(), t);
 }