You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Andrea Francia <an...@andreafrancia.it> on 2008/10/08 23:18:58 UTC
Why the getLastModified did not return a java.util.Date?
The FtpFile#getLastModified() method returns a long, why not a
java.util.Date?
public interface FtpFile {
/**
* Get last modified time.
*/
long getLastModified();
}
The behavior is not specified in the case the file does not exists.
--
Andrea Francia
http://andreafrancia.blogspot.com/2008/07/colinux-linux-dentro-windows.html
Re: Why the getLastModified did not return a java.util.Date?
Posted by Andrea Francia <an...@andreafrancia.it>.
Andrea Francia wrote:
> W.B. Garvelink wrote:
>> For a good dissertation on what's wrong with util.Date, read up on
>> Stephen Colebourne's summary of it wrt to JSR-310 date/time API:
>> http://www.parleys.com/display/PARLEYS/Home#slide=1;title=JSR%20310%20-%20Date%20and%20Time%20API;talk=7602357
>>
>> It's fairly comprehensive, and a lot more eloquent than I could
>> possibly explain it here.
>>
> I'll read that, thanks.
I view the presentation. I changed some of my thougth.
I think that a specific class should (almost) always preferred to
primitives but:
- the java.util.Date class sucks
- there is not a better standard alternative.
- hopingly the java.util.Date class will be superseeded by JSR-310
Instant class
But :
- the java.util.Date is standard and used in may existing libraries
- we can not yet use (in ftplet API) the Instant class
Now I can understand some justification of this design.
Thanks to all
--
Andrea Francia
http://andreafrancia.blogspot.com/2008/07/colinux-linux-dentro-windows.html
Re: Why the getLastModified did not return a java.util.Date?
Posted by Andrea Francia <an...@andreafrancia.it>.
W.B. Garvelink wrote:
> For a good dissertation on what's wrong with util.Date, read up on
> Stephen Colebourne's summary of it wrt to JSR-310 date/time API:
> http://www.parleys.com/display/PARLEYS/Home#slide=1;title=JSR%20310%20-%20Date%20and%20Time%20API;talk=7602357
> It's fairly comprehensive, and a lot more eloquent than I could
> possibly explain it here.
>
I'll read that, thanks.
> As for confusing, you've just proven my point:
> http://java.sun.com/javase/6/docs/api/java/util/Date.html#Date(int,%20int,%20int)
> (check out the range of the month number argument).
>
I agree that this is the badest month convention in the history.
> I'll admit that's a bit mean.
>
> Still, all that said, even if util.Date were immaculately designed and
> extremely elegant in use, I would still have chosen to use a long
> primitive in the FtpFile API. It's the simplest thing that could
> possibly work, it's directly assignable from
> java.io.File#lastModified()
I can always to new java.util.Date(java.io.File#lastModified()).
Is not directly assignable from a date that comes from database
(java.sql.Date).
> and, on the API level, there's no
> guarantee you ever need any of the value-add of a date class.
May be I want print a formatted date.
> Also, as
> Emmanuel pointed out, a long timestamp can be converted into any rich
> date class (be it java.util, Joda, JSR-310 or any other) via a single
> method call.
>
I'm not sure but I think that all those can convert in a single method
call from java.util.Date in their rich date class.
--
Andrea Francia
http://andreafrancia.blogspot.com/2008/07/colinux-linux-dentro-windows.html
Re: Why the getLastModified did not return a java.util.Date?
Posted by "W.B. Garvelink" <ba...@gmail.com>.
For a good dissertation on what's wrong with util.Date, read up on
Stephen Colebourne's summary of it wrt to JSR-310 date/time API:
http://www.parleys.com/display/PARLEYS/Home#slide=1;title=JSR%20310%20-%20Date%20and%20Time%20API;talk=7602357
It's fairly comprehensive, and a lot more eloquent than I could
possibly explain it here.
As for confusing, you've just proven my point:
http://java.sun.com/javase/6/docs/api/java/util/Date.html#Date(int,%20int,%20int)
(check out the range of the month number argument).
I'll admit that's a bit mean.
Still, all that said, even if util.Date were immaculately designed and
extremely elegant in use, I would still have chosen to use a long
primitive in the FtpFile API. It's the simplest thing that could
possibly work, it's directly assignable from
java.io.File#lastModified() and, on the API level, there's no
guarantee you ever need any of the value-add of a date class. Also, as
Emmanuel pointed out, a long timestamp can be converted into any rich
date class (be it java.util, Joda, JSR-310 or any other) via a single
method call.
Barend
On Thu, Oct 9, 2008 at 2:15 PM, Andrea Francia <an...@andreafrancia.it> wrote:
> W.B. Garvelink wrote:
>>
>> I wasn't involved in the design decision, but I would say a long is by
>> far the simplest, smallest in memory and most flexible way of
>> returning a time stamp.
>
> I doubt it is more flexible.
>
>> The util.date is bug-ridden,
>
> I doubt this java.util.Date is bug-ridden.
>
>> complicated,
>>
>
> I don't think, maybe that Calendar it's complicated.
>>
>> inflexible (90% of the api is deprecated)
>
> The fact that 90% is deprecated does not mean that java.util.Date is
> inflexible.
>>
>> and unnecessarily confusing
>>
>
> Maybe. Where?
>>
>> with e.g. the zero-based months
>
> Zero based months are a convetion used by Calendar, not java.util.Date.
>>
>> and the odd interaction with Calendar,
>> (default) Locale, and (default) TimeZone,
>
> All those are relevant for the Calendar API not the java.util.Date.
> The java.util.Date simply wrap a long.
>>
>> all of which are irrelevant
>> to time-stamping a resource.
>>
>
> With a java.util.Date can simply formatted with String.format("%tX") it's
> recognized as a date by many other library functions.
>
> --
> Andrea Francia
> http://andreafrancia.blogspot.com/2008/07/colinux-linux-dentro-windows.html
>
>
Re: Why the getLastModified did not return a java.util.Date?
Posted by Andrea Francia <an...@andreafrancia.it>.
Emmanuel Lecharny wrote:
> Andrea Francia wrote:
>> W.B. Garvelink wrote:
>>> I wasn't involved in the design decision, but I would say a long is by
>>> far the simplest, smallest in memory and most flexible way of
>>> returning a time stamp.
>> I doubt it is more flexible.
>
> Date myDate = new Date( getlastModified() );
Is not more flexible of
public interface FtpFile {
java.util.Date getLastModified();
}
long dateInMillis = file.getLastModified().getTime();
But with java.util.Date we can print formatted date with
System.out.printf("%tF", file.getLastModified());
And there are many library that uses java.util.Date() and the date
returned by databases are java.sql.Date (which extends java.util.Date).
Then why don't use a array of chars for representing strings?
java.util.Date is not a perfect date API, but there is not other best
choiches in the standard library.
Probably the Java 7 will provide a better date API.
>
> pretty flexible. And simple.
>
>
--
Andrea Francia
http://andreafrancia.blogspot.com/2008/07/colinux-linux-dentro-windows.html
Re: Why the getLastModified did not return a java.util.Date?
Posted by Emmanuel Lecharny <el...@gmail.com>.
Andrea Francia wrote:
> W.B. Garvelink wrote:
>> I wasn't involved in the design decision, but I would say a long is by
>> far the simplest, smallest in memory and most flexible way of
>> returning a time stamp.
> I doubt it is more flexible.
Date myDate = new Date( getlastModified() );
pretty flexible. And simple.
--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org
Re: Why the getLastModified did not return a java.util.Date?
Posted by Andrea Francia <an...@andreafrancia.it>.
W.B. Garvelink wrote:
> I wasn't involved in the design decision, but I would say a long is by
> far the simplest, smallest in memory and most flexible way of
> returning a time stamp.
I doubt it is more flexible.
> The util.date is bug-ridden,
I doubt this java.util.Date is bug-ridden.
> complicated,
>
I don't think, maybe that Calendar it's complicated.
> inflexible (90% of the api is deprecated)
The fact that 90% is deprecated does not mean that java.util.Date is
inflexible.
> and unnecessarily confusing
>
Maybe. Where?
> with e.g. the zero-based months
Zero based months are a convetion used by Calendar, not java.util.Date.
> and the odd interaction with Calendar,
> (default) Locale, and (default) TimeZone,
All those are relevant for the Calendar API not the java.util.Date.
The java.util.Date simply wrap a long.
> all of which are irrelevant
> to time-stamping a resource.
>
With a java.util.Date can simply formatted with String.format("%tX")
it's recognized as a date by many other library functions.
--
Andrea Francia
http://andreafrancia.blogspot.com/2008/07/colinux-linux-dentro-windows.html
Re: Why the getLastModified did not return a java.util.Date?
Posted by "W.B. Garvelink" <ba...@gmail.com>.
I wasn't involved in the design decision, but I would say a long is by
far the simplest, smallest in memory and most flexible way of
returning a time stamp. The util.date is bug-ridden, complicated,
inflexible (90% of the api is deprecated) and unnecessarily confusing
with e.g. the zero-based months and the odd interaction with Calendar,
(default) Locale, and (default) TimeZone, all of which are irrelevant
to time-stamping a resource.
On 10/8/08, Andrea Francia <an...@andreafrancia.it> wrote:
> The FtpFile#getLastModified() method returns a long, why not a
> java.util.Date?
>
> public interface FtpFile {
>
> /**
> * Get last modified time.
> */
> long getLastModified();
> }
>
> The behavior is not specified in the case the file does not exists.
>
> --
> Andrea Francia
> http://andreafrancia.blogspot.com/2008/07/colinux-linux-dentro-windows.html
>
>