473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

what do c++/STL programmers do for time programming?

There are the C runtime library functions of course, but are there any STL
time or date related functions? I couldn't find any.
May 29 '07 #1
2 2754
On May 29, 9:34 am, "Angus" <nos...@gmail.comwrote:
There are the C runtime library functions of course, but are there any STL
time or date related functions? I couldn't find any.
Same as C, except these are declared in the std namespace.
Look at your <ctimeheader

May 29 '07 #2
In article <f3******************@news.demon.co.uk>,
"Angus" <no****@gmail.comwrote:
There are the C runtime library functions of course, but are there any STL
time or date related functions? I couldn't find any.
No, there are not. boost::date_time is being considered for a C++
technical report:

http://www.boost.org/doc/html/date_time.html

For simple date applications without much I/O needs I prefer my
homegrown date class:

http://home.twcny.rr.com/hinnant/cpp...rian_date.html

What I like about it is the difficult-to-get-wrong construction syntax:

date d = may/29/2007; // ok
date d = 29/may/2007; // doesn't compile
date d = day(29)/may/2007; // ok
date d = day(29)/5/2007; // ok

In general, if it compiles, you've got a non-ambiguous date
specification following one of these patterns:

d/m/y
m/d/y
y/m/d

There's no danger of getting Feb. 1 and Jan 2 mixed up:

date d(1, 2, 2007); // doesn't compile
date d = 1/2/2007; // doesn't compile
date d = jan/2/2007; // ok
date d = day(1)/2/2007; // ok
date d = day(1)/feb/2007; // ok
date d = year(2007)/feb/1; // ok

And then there's the usual date arithmetic and the ability to specify
holidays like Mother's Day (US) as:

date d = 2*sun/may/2007; // second Sunday in May, 2007

Last days of the month, or last weekdays of the month are similarly easy:

Print out last day of each month for 2004:

for (date d = jan/last/2004, end = dec/last/2004;
d <= end; d += month(1))
std::cout << d << '\n';

Print out last Saturday of every month in 2004:

for (date d = last*sat/jan/2004, end = last*sat/dec/2004;
d <= end; d += month(1))
std::cout << d << '\n';

It is a relatively light-weight value class with only two files (a
header and source):

class date
{
private:
unsigned long jdate_;
unsigned short year_;
unsigned char month_;
unsigned char day_;
...
};

(sizeof(date) == 8 on my platform)

Feel free to use it.

-Howard
May 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
55
by: amanda992004 | last post by:
Excluding the factors of the brain capability, i.e I am not asking about this factor, if you are a single, aside from enjoying coding or debugging, how do you make time to eat properly, i.e...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
8
by: Midnight Java Junkie | last post by:
Dear Colleagues: I feel that the dumbest questions are those that are never asked. I have been given the opportunity to get into .NET. Our organization has a subscription with Microsoft that...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
8
by: clintonG | last post by:
Every single time neophytes or converts ask about naming and style conventions what are they told by the majority consensus? The answer is "do what you prefer but do so consistently" right? Yes,...
23
by: marora | last post by:
I keep hearing about not to use 'go_to' in your code. However, I don't know what's the reasoning behind it? Can any one here shed some light? Thanks in advance, Manish
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.