Advertisement
Margoshinka

Time

Dec 29th, 2021 (edited)
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace ex1
  6. {
  7.     class Time : Base
  8.     {
  9.      
  10.         protected internal Time() : base()
  11.         {
  12.             if (I1 < 0) I1 = 24 + I1;
  13.             else if(I1 > 24)
  14.             {
  15.                 I1 = I1 / 24;
  16.                 I2 = I1 % 24;
  17.                
  18.             }
  19.             if (I3 < 0) I3 = 60+I3;
  20.             else if (I3 > 60)
  21.             {
  22.                 I2 = I3 / 60;
  23.                 I3 = I3 % 60;
  24.             }
  25.  
  26.  
  27.  
  28.             if (I2 < 0) I2 = 60+I2;
  29.             if (I2 > 60)
  30.             {
  31.                 I1 = I2 / 60;
  32.                 I2 = I2 % 60;
  33.             }
  34.            
  35.            
  36.                
  37.            
  38.  
  39.            
  40.         }
  41.  
  42.         protected internal Time(int a, int b, int c) : base(a, b, c)
  43.         {
  44.             if (I1 < 0) I1 = 24 + I1;
  45.             else if (I1 > 24)
  46.             {
  47.                 I1 = I1 / 24;
  48.                 I2 = I2+I1 % 24;
  49.  
  50.             }
  51.             if (I3 < 0) I3 = 60 + I3;
  52.             else if (I3 > 60)
  53.             {
  54.                 I2 =I2+ I3 / 60;
  55.                 I3 = I3 % 60;
  56.             }
  57.  
  58.  
  59.  
  60.             if (I2 < 0) I2 = 60 + I2;
  61.             if (I2 > 60)
  62.             {
  63.                 I1 =I1+ I2 / 60;
  64.                 I2 = I2 % 60;
  65.             }
  66.  
  67.         }
  68.         public static Time operator -(Time m1, Time m2)
  69.         {
  70.             Time m = new Time(m1.I1 - m2.I1, m1.I2 - m2.I2, m1.I3 - m2.I3);
  71.             return m;
  72.         }
  73.         public Time Add(int sec)
  74.         {
  75.             Time temp = new Time(this.I1,this.I2, this.I3 + sec);
  76.             return temp;
  77.         }
  78.         public override string ToString()
  79.         {
  80.             return I1.ToString() + ":" + I2.ToString() + ":" + I3.ToString();
  81.  
  82.         }
  83.     }
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement