/* * 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("@(#) TStyp.cc (Gunther Schadow) 06/30/96"); #pragma implementation #include "TStyp.h" #include "DataTypeCode.h" #include "xios.h" #include "misc.h" #include "logfile.h" #include "exception.h" #include #include #include result TStyp::input(istream& is) { if(isdebug(is)) FATAL("can't read from debug stream"); LOGDEBUG("hl7/astm"); _date.input(is); _time.input(is); if (!_date.ispresent() && !_time.ispresent()) unset(); else if (_date.isnull() && !_time.ispresent()) nullify(); /* else if((!_date.ispresent() || !_date.isnull()) && (_time.ispresent() || !_time.isnull())) TIMEBASE_SYNTAX_ERROR(is); */ else Timebase::set(); const char *del = getdel(is, Delimiters::cmplevel); if(match(is, del)) { char next_c = is.peek(); if(strchr("YMDHMS",next_c)) _prec = (precision)next_c; else _prec = pmax; } return SUCCESS; } void TStyp::output(ostream& os) const { if(ishl7er(os) || isastmer(os)) { LOGDEBUG("hl7/astm"); if (ispresent()) if (isnull()) os << NULLVAL; else { _date.output(os); _time.output(os); if(_prec != pmax) { const char del = *getdel(os, Delimiters::cmplevel); os << del << (char)_prec; } } } else { LOGDEBUG("debug"); os << DSBGR0 "TStyp" DSBGR1; if (!ispresent()) os << DSNOPS; else { if (isnull()) os << DSNULL; else { os << DSFRST; _date.output(os); os << DSSEPR; _time.output(os); os << DSSEPR DSBGR0 "precision" DSBGR1; if(_prec == pmax) os << DSNOPS; else os << DSFRST << (char)_prec; os << DSEGRP; } } os << DSEGRP; } } void stamp(TStyp &ts) { time_t ti = time(NULL); struct tm *tms = localtime(&ti); #if defined(hpux) || defined(linux) || defined(_AIX) # define TIMEZONE (-timezone) #else # define TIMEZONE (tms->tm_gmtoff) #endif int tzm = TIMEZONE / 60; LOGDEBUG("local time: %d/%d/%d %d:%d:%d %d %d:%d", (int)tms->tm_year, (int)tms->tm_mon, (int)tms->tm_mday, (int)tms->tm_hour, (int)tms->tm_min, (int)tms->tm_sec, (int)TIMEZONE, (int)(tzm / 60), (int)(tzm % 60)); ts.setPrec(TStyp::psecond); ts.setSec(tms->tm_sec); ts.setMin(tms->tm_min); ts.setHour(tms->tm_hour); ts.setDay(tms->tm_mday); ts.setMonth(tms->tm_mon + 1); ts.setYear(tms->tm_year + 1900); ts.setTimeZoneHours(tzm / 60); ts.setTimeZoneMin(tzm % 60); }