This whole subject is my number one pet hate: ambiguous date  
representation. Seriously, after y2k and all the associated messing  
about fixing broken dates, one would think people would want to  
prevent anything like that ever happening again!

IMNSHO, *all* dates should either be expressed as YYYY-MM-DD, or in a  
form using the three elements: month name; two-digit day number; four- 
digit year, in arbitrary order. Otherwise there will always be  
ambiguity, which will lessen slightly in 2013, and slightly more in  
2032, but will never go away as long as people insist on using  
"10/6/11" and calling it a date.

As for the problem in hand, I think the best solution would be to  
reject out of hand Strings that are ambiguous, and develop a tool for  
processing *collections* of "date" strings. This tool could infer  
which elements represented what by looking at the whole collection,  
and noticing patterns that give the clues needed to make the best  
guess, in much the same way as a human reader does.

--
Cheers,
Peter.

On 16 jan 2010, at 13.39, Stéphane Ducasse <[email protected]>  
wrote:

> no problem
> we were not criticizing your fix more the problem in general
> Would be nice to have a guessFrom:
>
> Stef
>
> On Jan 16, 2010, at 12:07 PM, David Hotham wrote:
>
>> Hello,
>>
>> The motivation behind this fix is that I am parsing historical  
>> stock data
>> obtained from Google, in which dates are provided like this: "15- 
>> Jan-10".
>> Of course I want this to read as 2010, not 1910.
>>
>> I agree that the existing solution (with or without my tweak) looks  
>> ugly.
>>
>> I gave brief consideration to a bigger fix which first checked what  
>> the
>> current year was and then calculated what century to add to a low  
>> date.
>> But, frankly, I couldn't be bothered.  I figure that a one- 
>> character fix
>> that is good for ten years isn't too bad.
>>
>> I am quite content to defer to others as to what the right solution  
>> is here.
>> So long as there ends up being a convenient way to read two-digit  
>> years
>> correctly, I'll be happy.
>>
>> David
>>
>>
>>
>> "Stéphane Ducasse" <[email protected]> wrote in
>> message news:[email protected]...
>>> hi guys
>>>
>>> can one of you give a look at the this fix because I'm confused.
>>> Kernel-DavidHotham.538
>>>
>>> year < 20 ifTrue: [year := 2000 + year]
>>> was
>>> year < 10 ifTrue: [year := 2000 + year]
>>>
>>> both solutions look strange to me.
>>>
>>> http://code.google.com/p/pharo/issues/detail?id=1749
>>>
>>>
>>> readFrom: aStream
>>> "Read a Date from the stream in any of the forms:
>>> <day> <monthName> <year> (5 April 1982; 5-APR-82)
>>> <monthName> <day> <year> (April 5, 1982)
>>> <monthNumber> <day> <year> (4/5/82)
>>> <day><monthName><year> (5APR82)"
>>> | day month year |
>>> aStream peek isDigit
>>> ifTrue: [day := Integer readFrom: aStream].
>>> [aStream peek isAlphaNumeric]
>>> whileFalse: [aStream skip: 1].
>>> aStream peek isLetter
>>> ifTrue: ["number/name... or name..."
>>> month := (String new: 10) writeStream.
>>> [aStream peek isLetter]
>>> whileTrue: [month nextPut: aStream next].
>>> month := month contents.
>>> day isNil
>>> ifTrue: ["name/number..."
>>> [aStream peek isAlphaNumeric]
>>> whileFalse: [aStream skip: 1].
>>> day := Integer readFrom: aStream]]
>>> ifFalse: ["number/number..."
>>> month := Month nameOfMonth: day.
>>> day := Integer readFrom: aStream].
>>> [aStream peek isAlphaNumeric]
>>> whileFalse: [aStream skip: 1].
>>> year := Integer readFrom: aStream.
>>>>> year < 20 ifTrue: [year := 2000 + year]
>>> ifFalse: [ year < 1900 ifTrue: [ year := 1900 + year]].
>>>
>>> ^ self
>>> year: year
>>> month: month
>>> day: day
>>
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [email protected]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [email protected]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to