Standard library: Dates & Times¶
Holocene calendar¶
Goal: create a function that returns the year in the Holocene calendar.
Steps:
Implement the
To_Holocene_Year
function.
Requirements:
The
To_Holocene_Year
extracts the year from a time object (Time
type) and returns the corresponding year for the Holocene calendar.
For positive (AD) years, the Holocene year is calculated by adding 10,000 to the year number.
Remarks:
In this exercise, we don't deal with BC years.
Note that the year component of the
Time
type from theAda.Calendar
package is limited to years starting with 1901.
List of events¶
Goal: create a system to manage a list of events.
Steps:
Implement the
Events
package.
Declare the
Event_Item
type.Declare the
Event_Items
type.Implement the
Events.Lists
package.
Declare the
Event_List
type.Implement the
Add
procedure.Implement the
Display
procedure.
Requirements:
The
Event_Item
type (from theEvents
package) contains the description of an event.
This description shall be stored in an access-to-string type.
The
Event_Items
type stores a list of events.
This will be used later to represent multiple events for a specific date.
You shall use a vector for this type.
The
Events.Lists
package contains the subprograms that are used in the test application.The
Event_List
type (from theEvents.Lists
package) maps a list of events to a specific date.
You must use the
Event_Items
type for the list of events.You shall use the
Time
type from theAda.Calendar
package for the dates.Since we expect the events to be ordered by the date, you shall use ordered maps for the
Event_List
type.Procedure
Add
adds an event into the list of events for a specific date.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>
You should use the auxiliary
Date_Image
function — available in the body of theEvents.Lists
package — to display the date in theYYYY-MM-DD
format.
Remarks:
Let's briefly illustrate the expected output of this system.
Consider the following example:
with Ada.Calendar; with Ada.Calendar.Formatting; use Ada.Calendar.Formatting; with Events.Lists; use Events.Lists; procedure Test is EL : Event_List; begin EL.Add (Time_Of (2019, 4, 16), "Item #2"); EL.Add (Time_Of (2019, 4, 15), "Item #1"); EL.Add (Time_Of (2019, 4, 16), "Item #3"); EL.Display; end Test;The expected output of the
Test
procedure must be:EVENTS LIST - 2019-04-15 - Item #1 - 2019-04-16 - Item #2 - Item #3