00001 /*************************************************************** 00002 * 00003 * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department, 00004 * University of Wisconsin-Madison, WI. 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); you 00007 * may not use this file except in compliance with the License. You may 00008 * obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 * 00018 ***************************************************************/ 00019 00020 00021 #ifndef __CLASSAD_UTIL_H__ 00022 #define __CLASSAD_UTIL_H__ 00023 00024 #include "classad/common.h" 00025 00026 BEGIN_NAMESPACE( classad ) 00027 00028 // macro for recognising octal digits 00029 #define isodigit(x) (( (x) - '0' < 8 ) && ((x) - '0' >= 0)) 00030 00031 // A structure which represents the Absolute Time Literal 00032 struct abstime_t 00033 { 00034 time_t secs; // seconds from the epoch (UTC) 00035 int offset; // seconds east of Greenwich 00036 }; 00037 00038 // Get a random number between 0 and something large--usually an int 00039 int get_random_integer(void); 00040 // Get a random number between 0 and 1 00041 double get_random_real(void); 00042 00043 /* This calculates the timezone offset of the given time for the current 00044 * locality. The returned value is the offset in seconds east of UTC. 00045 * If the optional no_dst parameter is set to true, the calculation is 00046 * made assuming no daylight saving time. 00047 */ 00048 long timezone_offset( time_t clock, bool no_dst = false ); 00049 00050 /* This converts a string so that sequences like \t 00051 * (two-characters, slash and t) are converted into the 00052 * correct characters like tab. It also converts octal sequences. 00053 */ 00054 void convert_escapes(std::string &text, bool &validStr); 00055 00056 void getLocalTime(time_t *now, struct tm *localtm); 00057 void getGMTime(time_t *now, struct tm *localtm); 00058 00059 void absTimeToString(const abstime_t &atime, std::string &buffer); 00060 void relTimeToString(double rtime, std::string &buffer); 00061 00062 void day_numbers(int year, int month, int day, int &weekday, int &yearday); 00063 int fixed_from_gregorian(int year, int month, int day); 00064 bool is_leap_year(int year); 00065 00066 int classad_isinf(double x); 00067 int classad_isnan(double x); 00068 00069 END_NAMESPACE // classad 00070 00071 #endif//__CLASSAD_UTIL_H__