Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. with Ada.Text_Io; use Ada.Text_Io;
  2. with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
  3.  
  4.  
  5. package body Time_Handling is
  6.  
  7.  
  8. procedure Get(Time : out Date_Type) is
  9. C : Character;
  10. begin
  11.  
  12.  
  13. Put("Mata in ett datum: ");
  14. Get(Time(1));
  15. if (Time(1) > 9999) or (Time(1) < 1) then
  16. raise Year_Error;
  17. end if;
  18. Get(C);
  19. Get(Time(2));
  20. if (Time(2) > 12) or (Time(2) < 1) then
  21. raise Month_Error;
  22. end if;
  23. Get(C);
  24. Get(Time(3));
  25. if (Time(2) = 1 or Time(2) = 3 or Time(2) = 5 or Time(2) = 7 or Time(2) = 8 or Time(2) = 10 or Time(2) = 12) then
  26. if (Time(3) > 31) or(Time(3) < 1) then
  27. raise Day_Error;
  28. end if;
  29. elsif (Time(2) = 4 or Time(2) = 6 or Time(2) = 9 or Time(2) = 11) then
  30. if (Time(3) > 30) or (Time(3) < 1) then
  31. raise Day_Error;
  32. end if;
  33. elsif (Time(2) = 2) then
  34. if (Time(3) > 28) or (Time(3) < 1) then
  35. raise Day_Error;
  36. end if;
  37. end if;
  38.  
  39. end Get;
  40. -------------------------------------------------------------------------------------------------------------------------------------
  41. procedure Put(Time : in Date_Type) is
  42.  
  43. begin
  44.  
  45. Put("Ett datum: ");
  46. Put(Time(1), Width => 0);
  47. Put("-");
  48. if (Time(2) < 10) then
  49. Put(0, Width => 0);
  50. Put(Time(2), Width => 0);
  51. else
  52. Put(Time(2), Width => 0);
  53. end if;
  54. Put("-");
  55. if (Time(3) < 10) then
  56. Put(0, Width => 0);
  57. Put(Time(3), Width => 0);
  58. else
  59. Put(Time(3), Width => 0);
  60. end if;
  61. New_Line;
  62. end Put;
  63.  
  64. ----------------------------------------------------------------
  65.  
  66. function Next_Date (Tid : in Date_Type) return Date_Type is
  67. Time : Date_Type;
  68. begin
  69. Time := Tid;
  70. Time(3) := Time(3)+1;
  71. if (Time(2) = 1 or Time(2) = 3 or Time(2) = 5 or Time(2) = 7 or Time(2) = 8 or Time(2) = 10 or Time(2) = 12) and (Time(3) > 31) then
  72. if Time(2) = 12 then
  73. Time(1) := Time(1)+1;
  74. Time(2) := 1;
  75. Time(3) := 1;
  76. else
  77.  
  78. Time(2) := Time(2)+1;
  79.  
  80. Time(3) := 1;
  81. end if;
  82.  
  83. elsif (Time(2) = 4 or Time(2) = 6 or Time(2) = 9 or Time(2) = 11) and (Time(3) > 30) then
  84.  
  85. Time(2) := Time(2)+1;
  86.  
  87. Time(3) := 1;
  88.  
  89.  
  90. elsif Time(2) = 2 and Time(3) > 28 then
  91. Time(2) := Time(2)+1;
  92.  
  93. Time(3) := 1;
  94.  
  95. end if;
  96. return(Time);
  97.  
  98. end Next_Date;
  99.  
  100. -----------------------------------------------------------------------------------------------------
  101.  
  102. function Previous_Date (Tid : in Date_Type) return Date_Type is
  103. Time : Date_Type;
  104. begin
  105. Time := Tid;
  106. Time(3) := Time(3)-1;
  107. if (Time(2) = 1 or Time(2) = 4 or Time(2) = 6 or Time(2) = 8 or Time(2) = 9 or Time(2) = 11 or Time(2) = 2) and (Time(3) < 1) then
  108. if Time(2) = 1 then
  109. Time(1) := Time(1)-1;
  110. Time(2) := 12;
  111. Time(3) := 31;
  112. else
  113.  
  114. Time(2) := Time(2)-1;
  115.  
  116. Time(3) := 31;
  117. end if;
  118.  
  119. elsif (Time(2) = 5 or Time(2) = 7 or Time(2) = 10 or Time(2) = 12) and (Time(3) < 1) then
  120.  
  121. Time(2) := Time(2)-1;
  122.  
  123. Time(3) := 30 ;
  124.  
  125.  
  126. elsif Time(2) = 3 and Time(3) < 1 then
  127. Time(2) := Time(2)-1;
  128.  
  129. Time(3) := 28;
  130.  
  131. end if;
  132. return(Time);
  133.  
  134. end Previous_Date;
  135.  
  136.  
  137.  
  138. function ">" (Left, Right : in Date_Type) return Boolean is
  139.  
  140. begin
  141. if Left(1) > Right(1) then
  142. return(True);
  143. elsif Left(1) < Right(1) then
  144. return(False);
  145. elsif Left(2) > Right(2) then
  146. return(True);
  147. elsif Left(2) < Right(2) then
  148. return(False);
  149. elsif Left(3) > Right(3) then
  150. return(True);
  151. elsif Left(3) < Right(3) then
  152. return(False);
  153. else
  154. return(False);
  155. end if;
  156.  
  157. end ">";
  158.  
  159.  
  160. function "<" (Left, Right : in Date_Type) return Boolean is
  161. begin
  162. if Left(1) < Right(1) then
  163. return(True);
  164. elsif Left(1) > Right(1) then
  165. return(False);
  166. elsif Left(2) < Right(2) then
  167. return(True);
  168. elsif Left(2) > Right(2) then
  169. return(False);
  170. elsif Left(3) < Right(3) then
  171. return(True);
  172. elsif Left(3) > Right(3) then
  173. return(False);
  174. else
  175. return(False);
  176. end if;
  177. end "<";
  178.  
  179.  
  180. function "=" (Left, Right : in Date_Type) return Boolean is
  181.  
  182. begin
  183. if (Left(1) = Right(1)) and (Left(2) = Right(2)) and (Left(3) = Right(3)) then
  184. return(True);
  185. else
  186. return(False);
  187. end if;
  188. end "=";
  189.  
  190. end Time_Handling;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement