todaysDate in localtime ?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

todaysDate in localtime ?

Dirk Eddelbuettel

In ql/time/date.cpp we have

    Date Date::todaysDate() {
        std::time_t t;

        if (std::time(&t) == std::time_t(-1)) // -1 means time() didn't work
            return Date();
        std::tm *gt = std::gmtime(&t);
        return Date(Day(gt->tm_mday),
                    Month(gt->tm_mon+1),
                    Year(gt->tm_year+1900));
    }

I'd like to be able to use std::localtime instead as I just got bitten when I
asked for todaysDate() here in UTC+6 and got tomorrow's date instead.  

Shall I add that with a binary toggle to turn localtime on/off with a default
to off, i.e. existing behaviour?

Other suggestions?  I'd also love a Date() constructor from "yyyymmdd" or
(long) yyyymmdd as just relying on the Applix/Excel number is a tad
restrictive.

Dirk

--
Three out of two people have difficulties with fractions.

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: todaysDate in localtime ?

Luigi Ballabio
On Fri, 2009-04-17 at 21:22 -0500, Dirk Eddelbuettel wrote:

> In ql/time/date.cpp we have
>
>     Date Date::todaysDate() {
>         std::time_t t;
>
>         if (std::time(&t) == std::time_t(-1)) // -1 means time() didn't work
>             return Date();
>         std::tm *gt = std::gmtime(&t);
>         return Date(Day(gt->tm_mday),
>                     Month(gt->tm_mon+1),
>                     Year(gt->tm_year+1900));
>     }
>
> I'd like to be able to use std::localtime instead as I just got bitten when I
> asked for todaysDate() here in UTC+6 and got tomorrow's date instead.  
>
> Shall I add that with a binary toggle to turn localtime on/off with a default
> to off, i.e. existing behaviour?

Ouch.  You're right.  We should probably use localtime as the default.
Objections?


> I'd also love a Date() constructor from "yyyymmdd" or
> (long) yyyymmdd as just relying on the Applix/Excel number is a tad
> restrictive.

You can use DateParser in <ql/utilities/dataparsers.hpp>.

Luigi


--

Don't let school get in the way of your education.
-- Mark Twain



------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: todaysDate in localtime ?

Ferdinando Ametrano-4
On Mon, Apr 20, 2009 at 5:51 PM, Luigi Ballabio
<[hidden email]> wrote:
>> In ql/time/date.cpp
>> [...]
> [...]
> We should probably use localtime as the default.
> Objections?

I agree

ciao -- Nando

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: todaysDate in localtime ?

Luigi Ballabio
On Mon, 2009-04-20 at 18:24 +0200, Ferdinando Ametrano wrote:
> > We should probably use localtime as the default.
> > Objections?
>
> I agree

Done.

Luigi


--

Perfection is reached, not when there is no longer anything to add, but
when there is no longer anything to take away.
-- Antoine de Saint-Exupery



------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: todaysDate in localtime ?

Dirk Eddelbuettel

On 21 April 2009 at 14:20, Luigi Ballabio wrote:
| On Mon, 2009-04-20 at 18:24 +0200, Ferdinando Ametrano wrote:
| > > We should probably use localtime as the default.
| > > Objections?
| >
| > I agree
|
| Done.

Perfect. I actually did the same in quick local copy of the function.
localtime() does make more sense.

Dirk

--
Three out of two people have difficulties with fractions.

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev