source: trunk/drmaa_utils/drmaa_utils/datetime.h @ 1

Revision 1, 3.5 KB checked in by mmamonski, 13 years ago (diff)

Torque/PBS DRMAA initial commit

Line 
1/* $Id: datetime.h 296 2010-09-15 13:21:14Z mmatloka $ */
2/*
3 *  FedStage DRMAA utilities library
4 *  Copyright (C) 2006-2008  FedStage Systems
5 *
6 *  This program is free software: you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation, either version 3 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/**
21 * @file datetime.h
22 * DRMAA and ISO-8601 date/time parser.
23 */
24
25#ifndef __DRMAA_UTILS__DATETIME_H
26#define __DRMAA_UTILS__DATETIME_H
27
28#include <drmaa_utils/common.h>
29
30/**
31 * @defgroup datetime  DRMAA date/time parser.
32 *
33 * It parses date/time string in format of
34 * drmaa_start_time and drmaa_deadline_time attributes.
35 * In other words it accepts time in following format:
36 *
37 * <tt>  [[[[CC]YY/]MM/]DD] hh:mm[:ss] [{-|+}UU:uu]  </tt>
38 *
39 * where
40 *    CC is the first two digits of the year (century-1),
41 *    YY is the last two digits of the year,
42 *    MM is the two digits of the month [01,12],
43 *    DD is the two-digit day of the month [01,31],
44 *    hh is the two-digit hour of the day [00,23],
45 *    mm is the two-digit minute of the day [00,59],
46 *    ss is the two-digit second of the minute [00,61],
47 *    UU is the two-digit hours since (before) UTC,
48 *    uu is the two-digit minutes since (before) UTC.
49 */
50/* @{ */
51
52typedef struct fsd_datetime_s fsd_datetime_t;
53
54/**
55 * Parses date/time.
56 * @param string  Textual representation to date/time.
57 * @return Absolute time according to string.
58 */
59time_t fsd_datetime_parse( const char *string );
60
61/**
62 * Return first timestamp after \a t
63 * which match date/time pattern \a dt.
64 */
65time_t fsd_datetime_after( fsd_datetime_t *dt, time_t t );
66
67/**
68 * Fill unset fields of fsd_datetime_t structure according to timestamp.
69 * @param dt   Will be filled with local time representation of filler.
70 * @param filler  Seconds since epoch.
71 */
72void fsd_datetime_fill( fsd_datetime_t *dt, time_t filler );
73
74/** Makes UTC datetime from (possibly not absolute) fsd_datetime_t. */
75time_t fsd_datetime_mktime( const fsd_datetime_t *dt );
76
77enum{
78        FSD_DT_YEAR         = 1<<0,
79        FSD_DT_MONTH        = 1<<1,
80        FSD_DT_DAY          = 1<<2,
81        FSD_DT_HOUR         = 1<<3,
82        FSD_DT_MINUTE       = 1<<4,
83        FSD_DT_SECOND       = 1<<5,
84        FSD_DT_TZ_DELTA     = 1<<6,
85        FSD_DT_ALL = FSD_DT_YEAR | FSD_DT_MONTH | FSD_DT_DAY
86                | FSD_DT_HOUR | FSD_DT_MINUTE | FSD_DT_SECOND | FSD_DT_TZ_DELTA
87};
88
89/** Intermediate result of parsing date/time string (may be incomplete). */
90struct fsd_datetime_s {
91        unsigned mask;  /**< Bit-set of fields which were set. */
92        int year;       /**< Year. */
93        int month;      /**< Month. */
94        int day;        /**< Day. */
95        int hour;       /**< Hour. */
96        int minute;     /**< Minute. */
97        int second;     /**< Second. */
98        long tz_delta;  /**< Timezone; Number of seconds ahead of UTC. */
99};
100
101
102/**
103 * Guess local timezone for given UTC time
104 * @param t UTC timestamp (time from epoch).
105 * @return Numbef of seconds east (since/before) UTC.  For example in CET
106 * +3600 is returned (UTC + 1 hour).
107 */
108long fsd_timezone( time_t t );
109
110/* @} */
111
112void
113fsd_datetime_dump( const fsd_datetime_t *dt, char *s, size_t len );
114
115#endif /* __DRMAA_UTILS__DATETIME_H */
116
Note: See TracBrowser for help on using the repository browser.