time.hpp

    1: #ifndef TIME_HPP
    2: #define TIME_HPP
    3: /*------------------------------------------------------------------------------
    4: 
    5:   Author:    Andy Rushton
    6:   Copyright: (c) Andy Rushton, 2004
    7:   License:   BSD License, see ../docs/license.html
    8: 
    9:   Simplified access to representations of time and conversions between them.
   10:   The motivation for this package is that the low-level system calls for
   11:   accessing time are ugly and therefore potentially error-prone. I hope that
   12:   this interface is much simpler and therefore easier to use and more likely
   13:   to yield first-time right programs.
   14: 
   15:   time is represented as the built-in integer type time_t - this is the
   16:   standard representation of system time in computerland and represents the
   17:   number of seconds since midnight 1 Jan 1970, believe it or not.
   18: 
   19:   Functions are provided here for converting to and from more
   20:   human-comprehendable forms.
   21: 
   22: ------------------------------------------------------------------------------*/
   23: #include "os_fixes.hpp"
   24: #include <time.h>
   25: #include <string>
   26: 
   27: // get the integer representing the time now
   28: time_t time_now(void);
   29: 
   30: // get the integer representing the requested time - the local time is expressed in the local timezone
   31: time_t localtime_create(int year, int month, int day, int hour, int minute, int second);
   32: 
   33: // extract human-centric form of the machine representation time_t
   34: int localtime_year(time_t);    // the year e.g. 1962
   35: int localtime_month(time_t);   // the month, numbered 1-12 e.g. August = 8
   36: int localtime_day(time_t);     // the day of the month numbered 1-31 e.g. 29
   37: int localtime_hour(time_t);    // the hour of day numbered 0-23
   38: int localtime_minute(time_t);  // minute past the hour numbered 0-59
   39: int localtime_second(time_t);  // second past the minute numbered 0-59
   40: int localtime_weekday(time_t); // the day of the week numbered 0-6 with 0=Sunday
   41: int localtime_yearday(time_t); // the number of days into the year
   42: 
   43: // convert the integer representation of time to a human-readable form
   44: std::string localtime_string(time_t);
   45: 
   46: #endif