Standard library: Dates & Times

Holocene calendar

Goal: create a function that returns the year in the Holocene calendar.

Steps:

1. Implement the `To_Holocene_Year` function.

Requirements:

1. The `To_Holocene_Year` extracts the year from a time object (`Time` type) and returns the corresponding year for the Holocene calendar.

1. For positive (AD) years, the Holocene year is calculated by adding 10,000 to the year number.

Remarks:

1. In this exercise, we don't deal with BC years.

2. Note that the year component of the `Time` type from the `Ada.Calendar` package is limited to years starting with 1901.

```

function To_Holocene_Year (T : Time) return Integer is
begin
return 0;
end To_Holocene_Year;

with To_Holocene_Year;

procedure Main is
type Test_Case_Index is
(Holocene_Chk);

procedure Display_Holocene_Year (Y : Year_Number) is
HY : Integer;
begin
HY := To_Holocene_Year (Time_Of (Y, 1, 1));
Put_Line ("Year (Gregorian): " & Year_Number'Image (Y));
Put_Line ("Year (Holocene):  " & Integer'Image (HY));
end Display_Holocene_Year;

procedure Check (TC : Test_Case_Index) is
begin
case TC is
when Holocene_Chk =>
Display_Holocene_Year (2012);
Display_Holocene_Year (2020);
end case;
end Check;

begin
if Argument_Count < 1 then
Put_Line ("ERROR: missing arguments! Exiting...");
return;
elsif Argument_Count > 1 then
end if;

Check (Test_Case_Index'Value (Argument (1)));
end Main;

Use tabbed editor view

Use the dark theme

-g

-O0

-gnata

-gnatW8

-gnatwa

-gnatyg0-s

-gnatyM50

-gnatyM80

-gnato

-gnato0

-gnato11

-gnato21

-gnato22

-gnato23

-gnateE

-gnatX

```

List of events

Goal: create a system to manage a list of events.

Steps:

1. Implement the `Events` package.

1. Declare the `Event_Item` type.

2. Declare the `Event_Items` type.

2. Implement the `Events.Lists` package.

1. Declare the `Event_List` type.

2. Implement the `Add` procedure.

3. Implement the `Display` procedure.

Requirements:

1. The `Event_Item` type (from the `Events` package) contains the description of an event.

1. This description shall be stored in an access-to-string type.

2. The `Event_Items` type stores a list of events.

1. This will be used later to represent multiple events for a specific date.

2. You shall use a vector for this type.

3. The `Events.Lists` package contains the subprograms that are used in the test application.

4. The `Event_List` type (from the `Events.Lists` package) maps a list of events to a specific date.

1. You must use the `Event_Items` type for the list of events.

2. You shall use the `Time` type from the `Ada.Calendar` package for the dates.

3. Since we expect the events to be ordered by the date, you shall use ordered maps for the `Event_List` type.

5. Procedure `Add` adds an event into the list of events for a specific date.

6. Procedure `Display` must display all events for each date (ordered by date) using the following format:

```<event_date #1>
<description of item #1a>
<description of item #1b>
<event_date #2>
<description of item #2a>
<description of item #2b>
```
1. You should use the auxiliary `Date_Image` function — available in the body of the `Events.Lists` package — to display the date in the `YYYY-MM-DD` format.

Remarks:

1. Let's briefly illustrate the expected output of this system.

1. Consider the following example:

```with Ada.Calendar;

with Events.Lists;            use Events.Lists;

procedure Test is
EL : Event_List;
begin
"Item #2");
"Item #1");
"Item #3");
EL.Display;
end Test;
```
2. The expected output of the `Test` procedure must be:

```EVENTS LIST
- 2019-04-15
- Item #1
- 2019-04-16
- Item #2
- Item #3
```
```

package Events is

type Event_Item is null record;

type Event_Items is null record;

end Events;

package Events.Lists is

type Event_List is tagged private;

procedure Add (Events     : in out Event_List;
Event_Time :        Time;
Event      :        String);

procedure Display (Events : Event_List);

private

type Event_List is tagged null record;

end Events.Lists;

package body Events.Lists is

procedure Add (Events     : in out Event_List;
Event_Time : Time;
Event      : String) is
begin
null;

function Date_Image (T : Time) return String is
Date_Img : constant String := Image (T);
begin
return Date_Img (1 .. 10);
end;

procedure Display (Events : Event_List) is
T : Time;
begin
Put_Line ("EVENTS LIST");
--  You should use Date_Image (T) here!
end Display;

end Events.Lists;

with Events.Lists;            use Events.Lists;

procedure Main is
type Test_Case_Index is
(Event_List_Chk);

procedure Check (TC : Test_Case_Index) is
EL : Event_List;
begin
case TC is
when Event_List_Chk =>
"Final check");
"Release");
"Brother's birthday");
"New Year's Day");
EL.Display;
end case;
end Check;

begin
if Argument_Count < 1 then
Put_Line ("ERROR: missing arguments! Exiting...");
return;
elsif Argument_Count > 1 then
end if;

Check (Test_Case_Index'Value (Argument (1)));
end Main;

Use tabbed editor view

Use the dark theme

-g

-O0

-gnata

-gnatW8

-gnatwa

-gnatyg0-s

-gnatyM50

-gnatyM80

-gnato

-gnato0

-gnato11

-gnato21

-gnato22

-gnato23

-gnateE

-gnatX

```