Login  Register

Re: todaysDate in localtime ?

Posted by Luigi Ballabio on Apr 20, 2009; 3:51pm
URL: http://quantlib.414.s1.nabble.com/todaysDate-in-localtime-tp12737p12738.html

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