Why couldn't you do something like this?  It is type stable:

using Base.Dates
leapDay = isleapyear(yr) ? Date(yr, 2, 29) : Date()

if leapDay != Date()
   doy = dayofyear( leapDay )
end

Again, Date() returns this: *0001-01-01*

It works nicely as a "null" date.

Chris

On Tuesday, February 9, 2016 at 11:28:51 PM UTC-5, Michael Landis wrote:
>
> missed a paren above (for the people that are going to past the code into 
> a shell and try it out) - something that I am not doing.  Still, this is 
> closer:
>
> # wishful thinking...
> using Dates;
> leapDay = isleapyear(yr) ? Date(yr,2,29) : nothing
> if ! leapDay
>   doy = dayofyear( leapDay )
>   ...   clean and concise (thought that was the point), but we get
>
> leapDay = isleapyear (yr)?  Nullable {Date} (Date (yr, 2:29)): Nullable 
> {Date} ()
> if ! isnull( leapDay )
>   doy = dayofyear( get(leapDay) )
>
> On Tue, Feb 9, 2016 at 8:22 PM, Michael Landis <[email protected] 
> <javascript:>> wrote:
>
>> # wishful thinking...
>> using Dates;
>> leapDay = isleapyear(yr) ? Date(yr,2,29) : nothing
>> if ! leapDay
>>   dow = dayofyear( leapDay )
>>   ...   clean and concise (thought that was the point), but we get
>>
>> leapDay = isleapyear(yr) ? Nullable{Date}( Date(yr,2,29) : 
>> Nullable{Date}()
>> if ! isnull( leapDay )
>>   dow = dayofyear( get(leapDay) )
>>   ...
>>
>> If I am dumb enough to forget to check for a null date, I deserve the 
>> exception - the code would be wrong.  Making me type two or three times as 
>> many characters, obscuring what is actually going on, ... all to eliminate 
>> NullPointerExceptions?  I have to write exception free code anyway, so all 
>> I have 'gained' is a lot of superfluous verbosity.  I'm going to side with 
>> salience over verbosity every time.  The type safe argument just doesn't 
>> sell me, sorry.
>>
>
>

Reply via email to