From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7dadb26e573572d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-08 20:48:19 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!82-43-33-75.cable.ubr01.croy.blueyonder.co.UK!not-for-mail From: Nick Roberts Newsgroups: comp.lang.ada Subject: Re: ada calendar Date: Tue, 09 Dec 2003 04:48:10 +0000 Message-ID: References: <4948f537.0312060753.6b03e2ef@posting.google.com> NNTP-Posting-Host: 82-43-33-75.cable.ubr01.croy.blueyonder.co.uk (82.43.33.75) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1070945298 74751616 82.43.33.75 ([25716]) User-Agent: Mozilla/5.0 (Windows; U; Win95; en-GB; rv:1.5) Gecko/20031007 X-Accept-Language: en-gb, en, en-us In-Reply-To: Xref: archiver1.google.com comp.lang.ada:3256 Date: 2003-12-09T04:48:10+00:00 List-Id: Pascal Obry wrote: > Marius Amado Alves writes: > >>You can do it with Ada.Calendar: >> >> Your_Function (Time_Of >> (Year_Number'Value (S (7 .. 10)), >> Month_Number'Value (S (4 .. 5)), >> Day_Number'Value (S (1 .. 2)))); >> >>where S is your string containing "27/06/2003" or similar. > > There is no guarantee that S start to 1. It should be using S'First as > offset to compute all slices. True, but there's an alternative technique, and possibly a better one in this kind of case, using implicit array conversion: subtype Date_String is String(1..10); X: constant Date_String := S; -- checks length and slides if necessary ... if X(3) /= '/' or X(6) /= '/' then raise ...; end if; Your_Function( Time_Of( Year_Number'Value ( X(7..10) ), Month_Number'Value( X(4..5) ), Day_Number'Value ( X(1..2) ) ) ); Obviously, if possible, it is desirable to declare S itself of a subtype such as Date_String. This technique shows the person reading (reviewing) the code that X does indeed start at 1. If the declaration of Date_String is distant from the use of a variable of this subtype, you can always use an 'if' test (or pragma Assert, or a comment) to reiterate that the bounds are 1 and 10. -- Nick Roberts