1 //============================================================================== 2 // 3 // This file is part of GPSTk, the GPS Toolkit. 4 // 5 // The GPSTk is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published 7 // by the Free Software Foundation; either version 3.0 of the License, or 8 // any later version. 9 // 10 // The GPSTk is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public 16 // License along with GPSTk; if not, write to the Free Software Foundation, 17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 18 // 19 // This software was developed by Applied Research Laboratories at the 20 // University of Texas at Austin. 21 // Copyright 2004-2020, The Board of Regents of The University of Texas System 22 // 23 //============================================================================== 24 25 //============================================================================== 26 // 27 // This software was developed by Applied Research Laboratories at the 28 // University of Texas at Austin, under contract to an agency or agencies 29 // within the U.S. Department of Defense. The U.S. Government retains all 30 // rights to use, duplicate, distribute, disclose, or release this software. 31 // 32 // Pursuant to DoD Directive 523024 33 // 34 // DISTRIBUTION STATEMENT A: This software has been approved for public 35 // release, distribution is unlimited. 36 // 37 //============================================================================== 38 39 /// @file TimeString.hpp print and scan using all TimeTag derived classes. 40 41 #ifndef GPSTK_TIMESTRING_HPP 42 #define GPSTK_TIMESTRING_HPP 43 44 #include "TimeTag.hpp" 45 #include "CommonTime.hpp" 46 47 namespace gpstk 48 { 49 /// @ingroup TimeHandling 50 //@{ 51 52 /** 53 * The TimeTag classes are the "interface" for CommonTime, so 54 * when printing a CommonTime object, each of the TimeTag printf() 55 * functions are called to handle the print identifiers that it 56 * recognizes. The following is a list of these identifiers and 57 * the meaning for each: 58 * 59 * - ANSITime: 60 * - K integer seconds since Unix Epoch (00:00, Jan 1, 1970 UTC) 61 * 62 * - CivilTime: 63 * - Y integer 4-digit year 64 * - y integer 2-digit year 65 * - m integer month 66 * - b abbreviated month name string (e.g. "Jan") 67 * - B full month name string (e.g. "January") 68 * - d integer day-of-month 69 * - H integer hour-of-day 70 * - M integer minute-of-hour 71 * - S integer second-of-minute 72 * - f float second-of-minute 73 * 74 * - Week (GPS/BDS/GAL/QZS): 75 * - E integer GPS Epoch 76 * - F integer full (13-bit) GPS Week 77 * - G integer mod (10-bit) GPS Week 78 * - R integer BDS Epoch 79 * - D integer full BDS Week 80 * - e integer mod BDS Week 81 * - T integer GAL Epoch 82 * - L integer full GAL Week 83 * - l integer mod GAL Week 84 * - V integer QZS Epoch 85 * - h integer full QZS Week 86 * - i integer mod QZS Week - same as I 87 * - X integer IRNSS Epoch 88 * - O integer IRNSS week 89 * - o integer mod INRSS Week 90 * 91 * - WeekSecond (GPS/BDS/GAL/QZS): 92 * - w integer GPS day-of-week 93 * - g float GPS second-of-week 94 * 95 * - GPSWeekZcount: 96 * - w integer GPS day-of-week 97 * - z integer GPS Z-count 98 * - Z integer GPS Z-count 99 * - c integer 29-bit Z-count 100 * - C integer 32-bit Z-count 101 * 102 * - JulianDate: 103 * - J float Julian Date 104 * 105 * - MJD: 106 * - Q float Modified Julian Date 107 * 108 * - UnixTime: 109 * - U integer seconds since Unix Epoch (00:00, Jan 1, 1970 UTC) 110 * - u integer microseconds 111 * 112 * - PosixTime: 113 * - W integer seconds 114 * - N integer nanoseconds 115 * 116 * - YDSTime: 117 * - Y integer 4-digit year 118 * - y integer 2-digit year 119 * - j integer day-of-year 120 * - s integer second-of-day 121 * 122 * - Common Identifiers: 123 * - P string TimeSystem to compare with TimeSystem::Systems enum 124 */ 125 std::string printTime( const CommonTime& t, 126 const std::string& fmt ); 127 128 /// This function converts the given CommonTime into the templatized 129 /// TimeTag object, before calling the TimeTag's printf(fmt). If 130 /// there's an error in conversion, it instead calls printf(fmt, true) 131 /// to signal a conversion error. 132 template <class TimeTagType> printAs(const CommonTime & t,const std::string & fmt)133 std::string printAs( const CommonTime& t, 134 const std::string& fmt ) 135 { 136 TimeTagType ttt; 137 try 138 { 139 ttt.convertFromCommonTime(t); 140 return ttt.printf(fmt); 141 } 142 catch (InvalidRequest& ir) 143 { 144 return ttt.printError(fmt); 145 } 146 } 147 148 /// This function determines if the given format includes items 149 /// that would be printed by the TimeTag's printf(fmt); NB 150 /// except 'P' (system). In other words, determine if 151 /// printAs<T>(t,fmt) will not modify the string. 152 template <class TimeTagType> willPrintAs(const std::string & fmt)153 bool willPrintAs( const std::string& fmt ) 154 { 155 TimeTagType ttt; 156 std::string chars = ttt.getPrintChars(); 157 for(size_t i=0; i<chars.length(); i++) { 158 if(chars[i] == 'P') continue; 159 if(StringUtils::isLike(fmt,TimeTag::getFormatPrefixInt()+chars[i]) || 160 StringUtils::isLike(fmt,TimeTag::getFormatPrefixFloat()+chars[i])) 161 return true; 162 } 163 return false; 164 } 165 166 /// Fill the TimeTag object \a btime with time information found in 167 /// string \a str formatted according to string \a fmt. 168 void scanTime( TimeTag& btime, 169 const std::string& str, 170 const std::string& fmt ); 171 172 void scanTime( CommonTime& t, 173 const std::string& str, 174 const std::string& fmt ); 175 176 /** This function is like the other scanTime functions except that 177 * it allows mixed time formats. 178 * i.e. Year / 10-bit GPS week / seconds-of-week 179 * The time formats are filled in the following order: GPS Epoch, 180 * year, month, GPS Full Week, GPS 10-bit Week, day-of-week, 181 * day-of-month, day-of-year, 29-bit Zcount, 19-bit Zcount, hour, 182 * minute, second-of-week, second-of-day, second-of-minute. 183 * @note MJD, Julian Date, ANSI time, Unix time, and 32-bit Zcount are 184 * treated as stand-alone types and are not mixed with others if 185 * detected. 186 */ 187 void mixedScanTime( CommonTime& t, 188 const std::string& str, 189 const std::string& fmt ); 190 191 //@} 192 193 } // namespace 194 195 #endif // GPSTK_TIMESTRING_HPP 196