public static JwTimestamp CreateNowUtc(int utcOffset) { JwTimestamp ts = new JwTimestamp(); ts.SetNowUtc(); ts.SubtractHours(utcOffset); return ts; }
/** * Format the timestamp using the formats defined in * JwDateUtility.format() and JwTimeUtility.format(). */ public static String Format(JwTimestamp ts, String format) { String s = format; s = JwDateUtility.Format(ts.GetDate(), s); s = JwTimeUtility.Format(ts.GetTime(), s); return s; }
public String Format(JwTimestamp ts) { return JwUtility.Format( getFormat(), _datePolicy.format(ts.GetDate()), _timePolicy.format(ts.GetTime())); }
//# __________ PROTOCOL :: INSTANCE CREATION __________ #// public static JwTimestampInterval Create(JwTimestamp start, JwTimestamp end) { JwTimestampInterval ti; ti = new JwTimestampInterval(); ti.SetStart(start); ti.SetEnd(end); return ti; }
//# __________ PROTOCOL :: INSTANCE CREATION __________ #// public static JwTimestamp CreateTimestamp(JwDate d, JwTime t) { JwTimestamp ts; ts = new JwTimestamp(); ts.SetDate(d); ts.SetTime(t); return ts; }
public JwTimestamp InferActualDepartureFromActualArrival(JwTimestamp actualArrival) { JwTimestamp ts = actualArrival.GetTimestampCopy(); ts.AddDuration(GetTimezoneOffset()); ts.SubtractDuration(GetTransitDuration()); return ts; }
public VmTruck CreateTruckForScheduledArrival(JwTimestamp expectedArrivalLocalTs) { JwTimestamp expectedDepartureLocalTs = ComputeScheduledDepartureLocalTimestampFromScheduledArrival(expectedArrivalLocalTs); VmTruck truck = new VmTruck(); truck.ExpectedDepartureLocalTs = expectedDepartureLocalTs; truck.CarrierCode = CarrierCode; truck.Number = FlightNumber; truck.OriginAirportCode = OriginAirportCode; truck.DestinationAirportCode = DestinationAirportCode; return truck; }
public JwTimestamp ComputeScheduledDepartureLocalTimestampFromScheduledArrival(JwTimestamp scheduledArrivalTs) { JwTimestamp ts = scheduledArrivalTs.GetTimestampCopy(); ts.SubtractDuration( GetTransitDuration()); ts.SubtractDuration( GetTimezoneOffset()); return ts; }
public static String Format_m_dd_yy_h_mm_ss_am(JwTimestamp ts) { return JwDateUtility.Format_m_dd_yy(ts.GetDate()) + " " + JwTimeUtility.Format_h_mm_ss_am(ts.GetTime()); }
public bool IsOnOrAfter(JwTimestamp d) { return CompareTo(d) >= 0; }
//# __________ PROTOCOL :: CONTRUCTOR __________ #// public JwTimestampInterval() { _start = null; _end = null; }
public void SetEnd(JwTimestamp ts) { _end = ts; }
public bool IsAfter(JwTimestamp d) { return CompareTo(d) > 0; }
//# __________ PROTOCOL :: TESTING __________ #// public bool HasArrivedEarly(JwTimestamp scheduledArrivalTs) { if(ActualArrivalLocalTs == null) return false; return ActualArrivalLocalTs.IsBefore(scheduledArrivalTs); }
public static JwTimestamp CreateTimestamp(DateTime x) { // kludge (err) - need to learn how to check DateTime for empty //if ( dt == null ) return null; JwTimestamp ts = new JwTimestamp(); ts.Set(x); return ts; }
//# __________ PROTOCOL :: COMPARE (convenience) __________ #// public bool IsBefore(JwTimestamp d) { return CompareTo(d) < 0; }
public static JwTimestamp CreateNowUtc() { JwTimestamp ts = new JwTimestamp(); ts.SetNowUtc(); return ts; }
public bool IsOnOrBefore(JwTimestamp d) { return CompareTo(d) <= 0; }
public bool HasEnd(JwTimestamp ts) { return JwUtility.IsEqual(GetEnd(), ts); }
//# __________ PROTOCOL :: INTERSECTION __________ #// /** * @see containsInclusive */ public bool Contains(JwTimestamp t) { return ContainsInclusive(t); }
public bool HasStart(JwTimestamp ts) { return JwUtility.IsEqual(GetStart(), ts); }
public String GetTimeSinceLastLog() { if( _lastLogTime == null ) { return HandleFirstLogTime(); } JwTimestamp ts = JwTimestamp.CreateNowUtc(); if( _lastLogTime.IsAfter(ts) ) { WriteToLog("Current time earlier than last time! Resetting!\r\n"); return HandleFirstLogTime(); } JwDuration d = _lastLogTime.Difference(ts); int value = 0; String unit = null; if( d.IsLessThan(_minuteDuration) ) { value = d.GetSecond(); unit = "s"; } else if( d.IsLessThan( _hourDuration ) ) { value = d.GetMinute(); unit = "m"; } else if( d.IsLessThan( _dayDuration )) { value = d.GetHour(); unit = "h"; } else { value = d.GetDay(); unit = "d"; } String formattedValue = value + ""; formattedValue = JwUtility.LeftPad(formattedValue, 2, '0'); StringBuilder sb = new StringBuilder(); sb.Append("+"); sb.Append(formattedValue); sb.Append(unit); _lastLogTime = ts; return sb.ToString(); }
public void SetStart(JwTimestamp ts) { _start = ts; }
//# __________ PROTOCOL :: UTILITY __________ #// public JwDuration Difference(JwTimestamp ts) { JwDuration dateDifference = ts.GetDate().Difference(_date); JwDuration timeDifference = ts.GetTime().Difference(_time); JwDuration d = new JwDuration(); d.Add(dateDifference); d.Add(timeDifference); return d; }
public static String FormatIso(JwTimestamp ts) { return Format(ts, "{yyyy}-{mm}-{dd} {HH24}:{MM}:{SS}"); }
/** * Determine if I am between the start and end timestamp, also return true * if I am equal to either the start or end timestamp. */ public bool IsBetweenInclusive(JwTimestamp start, JwTimestamp end) { if ( start != null && IsBefore(start) ) return false; if ( end != null && IsAfter(end) ) return false; return true; }
/** * Determine if this interval contains the time. The test excludes * the start and end dates. */ public bool ContainsExclusive(JwTimestamp t) { if ( t == null ) return false; if ( HasStart() && GetStart().IsOnOrAfter(t) ) return false; if ( HasEnd() && GetEnd().IsOnOrBefore(t) ) return false; return true; }
public static String FormatXsdUtc(JwTimestamp ts) { return Format(ts, "{yyyy}-{mm}-{dd}T{HH24}:{MM}:{SS}Z"); }
public String HandleFirstLogTime() { _lastLogTime = JwTimestamp.CreateNowUtc(); StringBuilder sb = new StringBuilder(); sb.Append("Began logging at "); sb.Append(_lastLogTime.ToString()); sb.Append(" UTC \r\n"); WriteToLog(sb.ToString()); return("+00s"); }
public static String Format_mm_dd_yyyy_HH24_MM(JwTimestamp ts) { return Format(ts, "{mm}/{dd}/{yyyy} {HH24}:{MM}"); }