コード例 #1
0
        static void Main(string[] args)
        {
            TimeOfDay?early = null;

            while (early.Equals(null))
            {
                early = getTimeOfDayFromInput("Enter early time: ");
            }
            TimeOfDay earlyTime = (TimeOfDay)early;

            TimeOfDay?late = null;

            while (late.Equals(null))
            {
                late = getTimeOfDayFromInput("Enter late time: ");
            }
            TimeOfDay lateTime = (TimeOfDay)late;

            TimeInterval result = computeTimeDiff(earlyTime, lateTime);

            if (result.Equals(errorInterval))
            {
                Console.WriteLine("computeTimeDiff reported an error");
            }
            else
            {
                Console.WriteLine("The difference is {0} hours and {1} minutes", result.hours, result.minutes);
            }

            // Require the user to press a key to exit window
            Console.ReadKey();
        }
コード例 #2
0
        private static string BuildString(Date modifiedDate, TimeOfDay modifiedTime,
                                          Date?nullableModifiedDate, TimeOfDay?nullableModifiedTime)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("modifiedDate:").Append(modifiedDate).Append(",");
            sb.Append("modifiedTime:").Append(modifiedTime).Append(",");
            sb.Append("nullableModifiedDate:").Append(nullableModifiedDate == null ? "null" : nullableModifiedDate.ToString()).Append(",");
            sb.Append("nullableModifiedTime:").Append(nullableModifiedTime == null ? "null" : nullableModifiedTime.ToString());
            return(sb.ToString());
        }
コード例 #3
0
ファイル: TimeOfDay.cs プロジェクト: hunter04d/courser
 public bool Equals(TimeOfDay?other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Hour == other.Hour && Minute == other.Minute);
 }
コード例 #4
0
        public override TimeOfDay?ReadJson(JsonReader reader, Type objectType, TimeOfDay?existingValue,
                                           bool hasExistingValue,
                                           JsonSerializer serializer)
        {
            var jo = JObject.Load(reader);

            var hour   = int.Parse((string)jo["Hour"]);
            var minute = int.Parse((string)jo["Minute"]);
            var second = int.Parse((string)jo["Second"]);

            return(new TimeOfDay(hour, minute, second));
        }
コード例 #5
0
        public static TimeOfDay?GetTimeOfDay(string strTimeOfDay)
        {
            TimeOfDay?resultTimeOfDay = null;

            foreach (TimeOfDay timeOfDay in Enum.GetValues(typeof(TimeOfDay)))
            {
                if (timeOfDay.ToString().ToLower().Trim() == strTimeOfDay.ToLower().Trim())
                {
                    return(timeOfDay);
                }
            }
            return(resultTimeOfDay);
        }
コード例 #6
0
 /// <summary>
 /// Attempts to parse a TimeOfDay value from the specified text.
 /// </summary>
 /// <param name="value">Input string</param>
 /// <param name="result">The TimeOfDay resulting from parsing the string value</param>
 /// <returns>true if the value was parsed successfully, false otherwise</returns>
 internal static bool TryParseTimeOfDay(string value, out TimeOfDay?result)
 {
     try
     {
         result = PlatformHelper.ConvertStringToTimeOfDay(value);
         return(true);
     }
     catch (FormatException)
     {
         result = null;
         return(false);
     }
 }
コード例 #7
0
ファイル: TimeOfDay.cs プロジェクト: hunter04d/courser
        public int CompareTo(TimeOfDay?other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (ReferenceEquals(null, other))
            {
                return(1);
            }
            if (Hour == other.Hour)
            {
                return(Minute.CompareTo(other.Minute));
            }

            return(Hour.CompareTo(other.Hour));
        }
コード例 #8
0
        public string Order(string orderInput)
        {
            string[] inputArray = orderInput.Split(',').ToArray();

            string    timeOfDay      = inputArray[0];
            TimeOfDay?timeOfDayOrder = OrderingInputConverter.GetTimeOfDay(timeOfDay);

            if (timeOfDayOrder == null)
            {
                return(GetErrorMessage().Trim().TrimEnd(DISHES_CHAR_SEPARATOR));
            }

            string[] dishesTypesOrderIds = GetOnlyDishesTypes(inputArray);

            string resultOrder = BuildResultOrderMessage(dishesTypesOrderIds, timeOfDayOrder.Value);

            return(resultOrder);
        }
コード例 #9
0
        public void PassToll(TimeOfDay time)
        {
            if (_vehicle.IsTollFree())
            {
                return;
            }
            if (_day.IsTollFree)
            {
                return;
            }

            var nextFee = time.TollFee;

            if (_startOfTheHour == null)
            {
                _startOfTheHour = time;
            }

            if (time.Hour - _startOfTheHour.Value.Hour == 0 ||
                time.Hour - _startOfTheHour.Value.Hour == 1 && time.Minute < _startOfTheHour.Value.Minute)
            {
                TotalFee       -= _feeForThisHour;
                _feeForThisHour = Math.Max(_feeForThisHour, nextFee);
                TotalFee       += _feeForThisHour;
            }
            else
            {
                TotalFee       += nextFee;
                _feeForThisHour = nextFee;
                _startOfTheHour = time;
            }

            if (TotalFee > 60)
            {
                TotalFee = 60;
            }
        }
コード例 #10
0
 public TimeOfDay?GetNullableTimeOfDay([FromODataUri] TimeOfDay?id)
 {
     ThrowIfInsideThrowsController();
     return(id);
 }
コード例 #11
0
 public override void WriteJson(JsonWriter writer, TimeOfDay?value, JsonSerializer serializer)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
        /// <summary>
        /// Calculate and set the EndTimeOfDay using count, interval and StarTimeOfDay. This means
        /// that these must be set before this method is call.
        /// </summary>
        /// <param name="count"></param>
        /// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
        public DailyTimeIntervalScheduleBuilder EndingDailyAfterCount(int count)
        {
            if (count <= 0)
            {
                throw new ArgumentException("Ending daily after count must be a positive number!");
            }

            if (startTimeOfDayUtc == null)
            {
                throw new ArgumentException("You must set the StartDailyAt() before calling this EndingDailyAfterCount()!");
            }

            DateTimeOffset today = SystemTime.UtcNow();
            DateTimeOffset startTimeOfDayDate  = startTimeOfDayUtc.GetTimeOfDayForDate(today);
            DateTimeOffset maxEndTimeOfDayDate = TimeOfDay.HourMinuteAndSecondOfDay(23, 59, 59).GetTimeOfDayForDate(today);

            //apply proper offsets according to timezone
            TimeZoneInfo targetTimeZone = timeZone ?? TimeZoneInfo.Local;

            startTimeOfDayDate  = new DateTimeOffset(startTimeOfDayDate.DateTime, TimeZoneUtil.GetUtcOffset(startTimeOfDayDate.DateTime, targetTimeZone));
            maxEndTimeOfDayDate = new DateTimeOffset(maxEndTimeOfDayDate.DateTime, TimeZoneUtil.GetUtcOffset(maxEndTimeOfDayDate.DateTime, targetTimeZone));

            TimeSpan remainingMillisInDay = maxEndTimeOfDayDate - startTimeOfDayDate;
            TimeSpan intervalInMillis;

            if (intervalUnit == IntervalUnit.Second)
            {
                intervalInMillis = TimeSpan.FromSeconds(interval);
            }
            else if (intervalUnit == IntervalUnit.Minute)
            {
                intervalInMillis = TimeSpan.FromMinutes(interval);
            }
            else if (intervalUnit == IntervalUnit.Hour)
            {
                intervalInMillis = TimeSpan.FromHours(interval);
            }
            else
            {
                throw new ArgumentException("The IntervalUnit: " + intervalUnit + " is invalid for this trigger.");
            }

            if (remainingMillisInDay < intervalInMillis)
            {
                throw new ArgumentException("The startTimeOfDay is too late with given Interval and IntervalUnit values.");
            }

            long maxNumOfCount = remainingMillisInDay.Ticks / intervalInMillis.Ticks;

            if (count > maxNumOfCount)
            {
                throw new ArgumentException("The given count " + count + " is too large! The max you can set is " + maxNumOfCount);
            }

            TimeSpan       incrementInMillis = TimeSpan.FromTicks((count - 1) * intervalInMillis.Ticks);
            DateTimeOffset endTimeOfDayDate  = startTimeOfDayDate.Add(incrementInMillis);

            if (endTimeOfDayDate > maxEndTimeOfDayDate)
            {
                throw new ArgumentException("The given count " + count + " is too large! The max you can set is " + maxNumOfCount);
            }

            DateTime cal = SystemTime.UtcNow().Date;

            cal             = cal.Add(endTimeOfDayDate.TimeOfDay);
            endTimeOfDayUtc = TimeOfDay.HourMinuteAndSecondOfDay(cal.Hour, cal.Minute, cal.Second);
            return(this);
        }
コード例 #13
0
 /// <summary>
 /// The TimeOfDay for this trigger to end firing each day.
 /// </summary>
 /// <param name="timeOfDayUtc"></param>
 /// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
 public DailyTimeIntervalScheduleBuilder EndingDailyAt(TimeOfDay timeOfDayUtc)
 {
     endTimeOfDayUtc = timeOfDayUtc;
     return(this);
 }
コード例 #14
0
 /// <summary>
 /// The TimeOfDay for this trigger to start firing each day.
 /// </summary>
 /// <param name="timeOfDayUtc"></param>
 /// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
 public DailyTimeIntervalScheduleBuilder StartingDailyAt(TimeOfDay timeOfDayUtc)
 {
     startTimeOfDayUtc = timeOfDayUtc ?? throw new ArgumentException("Start time of day cannot be null!");
     return(this);
 }
コード例 #15
0
 public IActionResult UnboundFunction([FromODataUri] Date p1, [FromODataUri] TimeOfDay p2,
                                      [FromODataUri] Date?p3, [FromODataUri] TimeOfDay?p4)
 {
     return(Ok(BuildString(p1, p2, p3, p4)));
 }
コード例 #16
0
 public IActionResult BoundFunction(int key, [FromODataUri] Date modifiedDate, [FromODataUri] TimeOfDay modifiedTime,
                                    [FromODataUri] Date?nullableModifiedDate, [FromODataUri] TimeOfDay?nullableModifiedTime)
 {
     return(Ok(BuildString(modifiedDate, modifiedTime, nullableModifiedDate, nullableModifiedTime)));
 }
コード例 #17
0
ファイル: Feed.cs プロジェクト: philvessey/NextDepartures
 private DateTime GetDateTimeFromDeparture(DateTime zonedDateTime, int dayOffset, TimeOfDay?departureTime)
 {
     return(new DateTime(zonedDateTime.Year, zonedDateTime.Month, zonedDateTime.Day, departureTime.Value.Hours % 24, departureTime.Value.Minutes, departureTime.Value.Seconds).AddDays((departureTime.Value.Hours / 24) + dayOffset));
 }
コード例 #18
0
 //---------------------------------------------------
 public RandomEvent(string n, string succeed, string fail, CharacterGroup char1, CharacterGroup char2, Room?rReq, TimeOfDay?tod, Comparison comp1, Comparison comp2, StatEffect[] succEff, StatEffect[] failEff)
 {
     mName = n; succeedString = succeed; failString = fail; mCharacter1 = char1; mCharacter2 = char2; mRoomReq = rReq; mTimeReq = tod; statCheck1 = comp1; statCheck2 = comp2; succeedEffects = succEff; failEffects = failEff;
 }