예제 #1
0
        private static void PrzykladowaAplikacjaRozszerzonaOMilisekundy()
        {
            Console.WriteLine("\n======== Time ========");
            var timeOneParam    = new ms.Time(12);
            var timeTwoParams   = new ms.Time(23, 59);
            var timeThreeParams = new ms.Time(6, 12, 59);
            var timeFourParams  = new ms.Time(20, 40, 30, 900);
            var timeString      = new ms.Time("15:05:29.300");

            Console.WriteLine($"Konstruktor jeden argument (12): {timeOneParam}");
            Console.WriteLine($"Konstruktor dwa argumenty (23,59): {timeTwoParams}");
            Console.WriteLine($"Konstruktor trzy argumenty (6,12,59): {timeThreeParams}");
            Console.WriteLine($"Konstruktor cztery argumenty (20, 40, 30, 900): {timeFourParams}");
            Console.WriteLine($"Konstruktor string (15:05:29.300): {timeString}");

            var timeLater   = new ms.Time(20, 0, 0, 900);
            var timeEarlier = new ms.Time(10, 30, 0, 500);

            Console.WriteLine($"\n{timeLater} > {timeEarlier} : {timeLater > timeEarlier}");
            Console.WriteLine($"{timeLater} >= {timeEarlier} : {timeLater >= timeEarlier}");
            Console.WriteLine($"{timeLater} < {timeEarlier} : {timeLater < timeEarlier}");
            Console.WriteLine($"{timeLater} <= {timeEarlier} : {timeLater <= timeEarlier}");
            Console.WriteLine($"{timeLater} == {timeEarlier} : {timeLater == timeEarlier}");
            Console.WriteLine($"{timeLater} != {timeEarlier} : {timeLater != timeEarlier}");

            var fiveHoursTimePeriod = new ms.TimePeriod(5, 0);

            Console.WriteLine($"\n{timeLater} + {fiveHoursTimePeriod} = {timeLater + fiveHoursTimePeriod}");
            Console.WriteLine($"{timeLater} - {fiveHoursTimePeriod} = {timeLater - fiveHoursTimePeriod}");


            Console.WriteLine("\n======== TimePeriod ========");

            var timePeriodOneParam       = new ms.TimePeriod(600.300);
            var timePeriodTwoParams      = new ms.TimePeriod(24, 30);
            var timePeriodThreeParams    = new ms.TimePeriod(30, 20, 10.999);
            var timePeriodTwoTimeObjects = new ms.TimePeriod(timeEarlier, timeLater);
            var timePeriodString         = new ms.TimePeriod("24:24:24.024");

            Console.WriteLine($"Konstruktor jeden argument (600.300): {timePeriodOneParam}");
            Console.WriteLine($"Konstruktor dwa argumenty (24, 30): {timePeriodTwoParams}");
            Console.WriteLine($"Konstruktor trzy argumenty (30, 20, 10.999): {timePeriodThreeParams}");
            Console.WriteLine($"Konstruktor string (24:24:24.024): {timePeriodString}");
            Console.WriteLine($"Konstruktor dwa obiekty Time(10,30,0,900) (20,0,0,500) : {timePeriodTwoTimeObjects}");

            var timePeriodLonger  = new ms.TimePeriod(86400.200);
            var timePeriodShorter = new ms.TimePeriod(35000.999);

            Console.WriteLine($"\n{timePeriodLonger} > {timePeriodShorter} : {timePeriodLonger > timePeriodShorter}");
            Console.WriteLine($"{timePeriodLonger} >= {timePeriodShorter} : {timePeriodLonger >= timePeriodShorter}");
            Console.WriteLine($"{timePeriodLonger} < {timePeriodShorter} : {timePeriodLonger < timePeriodShorter}");
            Console.WriteLine($"{timePeriodLonger} <= {timePeriodShorter} : {timePeriodLonger <= timePeriodShorter}");
            Console.WriteLine($"{timePeriodLonger} == {timePeriodShorter} : {timePeriodLonger == timePeriodShorter}");
            Console.WriteLine($"{timePeriodLonger} != {timePeriodShorter} : {timePeriodLonger != timePeriodShorter}");

            Console.WriteLine($"\n{timePeriodLonger} + {timePeriodShorter} = {timePeriodLonger + timePeriodShorter}");
            Console.WriteLine($"{timePeriodLonger} - {timePeriodShorter} = {timePeriodLonger - timePeriodShorter}");
            Console.WriteLine($"{timePeriodLonger} * 2 = {timePeriodLonger * 2}");
            Console.WriteLine($"{timePeriodLonger} / 2 = {timePeriodLonger / 2}");
        }
        /// <summary>
        /// Subtract two given time periods
        /// </summary>
        /// <param name="first">TimePeriod instance</param>
        /// <param name="second">TimePeriod instance</param>
        /// <returns>New calculated time period instance</returns>
        public static TimePeriod Minus(TimePeriod first, TimePeriod second)
        {
            var secondsBetweenTwoTimePeriods = first._seconds - second._seconds;

            return(new TimePeriod(secondsBetweenTwoTimePeriods));
        }
 /// <summary>
 /// Subtract given time period from this instance
 /// </summary>
 /// <param name="other">TimePeriod instance</param>
 /// <returns>New calculated time period instance</returns>
 public TimePeriod Minus(TimePeriod other) => Minus(this, other);
        /// <summary>
        /// Add two given time periods
        /// </summary>
        /// <param name="first">TimePeriod instance</param>
        /// <param name="second">TimePeriod instance</param>
        /// <returns>New calculated time period instance</returns>
        public static TimePeriod Plus(TimePeriod first, TimePeriod second)
        {
            var secondsOfTwoTimePeriods = first._seconds + second._seconds;

            return(new TimePeriod(secondsOfTwoTimePeriods));
        }
 /// <summary>
 /// Add two given time periods
 /// </summary>
 /// <param name="other">TimePeriod instance</param>
 /// <returns>New calculated time period instance</returns>
 public TimePeriod Plus(TimePeriod other) => Plus(this, other);
 /// <summary>
 /// Compare two objects and determine which one is longer.
 /// Longer is the one with bigger values, starting from hours, then minutes, then seconds
 /// </summary>
 /// <param name="other">TimePeriod instance</param>
 /// <returns>Negative integer if shorter, 0 if equal, positive if longer</returns>
 public int CompareTo(TimePeriod other) => _seconds.CompareTo(other._seconds);
 /// <summary>
 /// Compare two time periods if they have same time interval
 /// </summary>
 /// <param name="other">TimePeriod instance</param>
 /// <returns>True if both interval are the same, false otherwise</returns>
 public bool Equals(TimePeriod other) => Math.Abs(_seconds - other._seconds) < 0.0001;