/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pg_config.h" IDENT("@(#) TMtyp.cc (Gunther Schadow) 12/19/96"); #pragma implementation #include "TMtyp.h" #include "xios.h" #include #include "exception.h" #include "logfile.h" TMtyp::TMtyp(int hour, int minute, int second, int tzHours, int tzMinutes, int frac) : Timebase(DataTypeCode::TMval) { set(_second, second, SecMin, SecMax); set(_minute, minute, MinMin, MinMax); set(_hour, hour, HourMin, HourMax); if(frac == FracUndef) _sec10000 = FracUndef; else set(_sec10000, frac, FracMin, FracMax); if(tzHours == TimeZoneUndef) _tzHours = TimeZoneUndef; else { set(_tzHours, tzHours, TimeZoneHoursMin, TimeZoneHoursMax); set(_tzMinutes, tzMinutes, TimeZoneMinMin, TimeZoneMinMax); } } TMtyp::TMtyp() : Timebase(DataTypeCode::TMval) { _hour = HourMin; _minute = MinMin; _second = SecMin; _sec10000 = FracUndef; _tzHours = TimeZoneUndef; } int TMtyp::getHour() const { if(ispresent() & !isnull()) return _hour; else FATAL("access into non-present object"); } int TMtyp::getMin() const { if(ispresent() & !isnull()) return _minute; else FATAL("access into non-present object"); } int TMtyp::getSec() const { if(ispresent() & !isnull()) return _second; else FATAL("access into non-present object"); } int TMtyp::getFrac() const { if(ispresent() & !isnull()) return _sec10000; else FATAL("access into non-present object"); } int TMtyp::getTimeZoneHours() const { if(ispresent() & !isnull()) return _tzHours; else FATAL("access into non-present object"); } int TMtyp::getTimeZoneMin() const { if(ispresent() & !isnull() & _tzHours != TimeZoneUndef) return _tzMinutes; else FATAL("access into non-present object"); } void TMtyp::unset() { _hour = HourMin; _minute = MinMin; _second = SecMin; _sec10000 = FracUndef; _tzHours = TimeZoneUndef; Timebase::unset(); } void TMtyp::nullify() { _hour = HourMin; _minute = MinMin; _second = SecMin; _sec10000 = FracUndef; _tzHours = TimeZoneUndef; Timebase::nullify(); } result TMtyp::input(istream& is) { if(isdebug(is)) FATAL("can't read from debug stream"); LOGDEBUG("hl7/astm"); if(no_value(is)) return SUCCESS; if( input_number(_hour, is, 2, HourMin, HourMax) == FAIL || input_number(_minute, is, 2, MinMin, MinMax) == FAIL) TIMEBASE_SYNTAX_ERROR(is); /* * Optional part follows */ char next_c = is.peek(); bool is_end = ( strchr(getdel(is),next_c) != NULL ); _tzHours = TimeZoneUndef; if(!is_end && (next_c != '+') && (next_c != '-')) { if(input_number(_second, is, 2, SecMin, SecMax) == FAIL) TIMEBASE_SYNTAX_ERROR(is); next_c = is.peek(); if(next_c == '.') /* fractional secons follow */ { is.get(); if(input_number(_sec10000, is, 4, FracMin, FracMax) == FAIL) TIMEBASE_SYNTAX_ERROR(is); next_c = is.peek(); } else _sec10000 = FracUndef; } else { _second = 0; _sec10000 = FracUndef; } if((next_c == '+') || (next_c == '-')) { int sign = (next_c == '-') ? -1 : 1; is.get(); if(input_number(_tzHours, is, 2, TimeZoneHoursMin, TimeZoneHoursMax) == FAIL || input_number(_tzMinutes, is, 2, TimeZoneMinMin, TimeZoneMinMax) == FAIL) TIMEBASE_SYNTAX_ERROR(is); else { _tzHours *= sign; _tzMinutes *= sign; } } else _tzHours=TimeZoneUndef; return SUCCESS; } void TMtyp::output(ostream& os) const { if(ishl7er(os) || isastmer(os)) { LOGDEBUG("hl7/astm"); if (ispresent()) if (isnull()) os << NULLVAL; else { os.form("%02d%02d%02d",_hour,_minute,_second); if(_sec10000 != FracUndef) os.form(".%04d", _sec10000); if(_tzHours != TimeZoneUndef) os.form("%+05d",_tzHours*100+_tzMinutes); } } else { LOGDEBUG("debug"); os << DSBGR0 "TMtyp" DSBGR1; if (!ispresent()) os << DSNOPS; else { if (isnull()) os << DSNULL; else { os << dec << DSFRST DSBGR0 "Hour" DSBGR1 DSFRST << _hour << DSEGRP DSSEPR DSBGR0 "Min" DSBGR1 DSFRST << _minute << DSEGRP DSSEPR DSBGR0 "Sec" DSBGR1 DSFRST << _second << DSEGRP DSSEPR DSBGR0 "Frac" DSBGR1; if(_sec10000 == FracUndef) os << DSNOPS; else os << DSFRST << _sec10000; os << DSEGRP DSSEPR << DSBGR0 "TimeZone" DSBGR1; if(_tzHours == TimeZoneUndef) os << DSNOPS; else { os << DSFRST DSBGR0 "Hours" DSBGR1 DSFRST << _tzHours << DSEGRP DSSEPR DSBGR0 "Min" DSBGR1 DSFRST << _tzMinutes << DSEGRP; } os << DSEGRP; } } os << DSEGRP; } }