// file : xsd/cxx/tree/date-time-ostream.txx // author : Boris Kolpackov // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include namespace xsd { namespace cxx { namespace tree { // time_zone // template std::basic_ostream& operator<< (std::basic_ostream& os, const time_zone& z) { short h = z.zone_hours (); short m = z.zone_minutes (); if (h == 0 && m == 0) { os << C ('Z'); } else { if (h < 0 || m < 0) { h = -h; m = -m; os << C ('-'); } else os << C ('+'); C f (os.fill (C ('0'))); os.width (2); os << h << C (':'); os.width (2); os << m; os.fill (f); } return os; } // gday // template std::basic_ostream& operator<< (std::basic_ostream& os, const gday& x) { C f (os.fill (C ('0'))); os.width (2); os << x.day (); os.fill (f); if (x.zone_present ()) { const time_zone& z (x); os << z; } return os; } // gmonth // template std::basic_ostream& operator<< (std::basic_ostream& os, const gmonth& x) { C f (os.fill (C ('0'))); os.width (2); os << x.month (); os.fill (f); if (x.zone_present ()) { const time_zone& z (x); os << z; } return os; } // gyear // template std::basic_ostream& operator<< (std::basic_ostream& os, const gyear& x) { C f (os.fill (C ('0'))); os.width (4); os << x.year (); os.fill (f); if (x.zone_present ()) { const time_zone& z (x); os << z; } return os; } // gmonth_day // template std::basic_ostream& operator<< (std::basic_ostream& os, const gmonth_day& x) { C f (os.fill (C ('0'))); os.width (2); os << x.month () << C ('-'); os.width (2); os << x.day (); os.fill (f); if (x.zone_present ()) { const time_zone& z (x); os << z; } return os; } // gyear_month // template std::basic_ostream& operator<< (std::basic_ostream& os, const gyear_month& x) { C f (os.fill (C ('0'))); os.width (4); os << x.year () << C ('-'); os.width (2); os << x.month (); os.fill (f); if (x.zone_present ()) { const time_zone& z (x); os << z; } return os; } // date // template std::basic_ostream& operator<< (std::basic_ostream& os, const date& x) { C f (os.fill (C ('0'))); os.width (4); os << x.year () << C ('-'); os.width (2); os << x.month () << C ('-'); os.width (2); os << x.day (); os.fill (f); if (x.zone_present ()) { const time_zone& z (x); os << z; } return os; } // time // template std::basic_ostream& operator<< (std::basic_ostream& os, const time& x) { C f (os.fill (C ('0'))); os.width (2); os << x.hours () << C (':'); os.width (2); os << x.minutes () << C (':'); os.width (9); std::ios_base::fmtflags ff ( os.setf (std::ios::fixed, std::ios::floatfield)); os << x.seconds (); os.setf (ff, std::ios::floatfield); os.fill (f); if (x.zone_present ()) { const time_zone& z (x); os << z; } return os; } // date_time // template std::basic_ostream& operator<< (std::basic_ostream& os, const date_time& x) { C f (os.fill (C ('0'))); os.width (4); os << x.year () << C ('-'); os.width (2); os << x.month () << C ('-'); os.width (2); os << x.day () << C ('T'); os.width (2); os << x.hours () << C (':'); os.width (2); os << x.minutes () << C (':'); os.width (9); std::ios_base::fmtflags ff ( os.setf (std::ios::fixed, std::ios::floatfield)); os << x.seconds (); os.setf (ff, std::ios::floatfield); os.fill (f); if (x.zone_present ()) { const time_zone& z (x); os << z; } return os; } // duration // template std::basic_ostream& operator<< (std::basic_ostream& os, const duration& x) { if (x.negative ()) os << C ('-'); os << C ('P'); // In case it is 0-duration, use the years field to handle // this case. // if (x.years () != 0 || (x.months () == 0 && x.days () == 0 && x.hours () == 0 && x.minutes () == 0 && x.seconds () == 0.0)) { os << x.years () << C ('Y'); } if (x.months () != 0) { os << x.months () << C ('M'); } if (x.days () != 0) { os << x.days () << C ('D'); } // Figure out if we need the 'T' delimiter. // if (x.hours () != 0 || x.minutes () != 0 || x.seconds () != 0.0) os << C ('T'); if (x.hours () != 0) { os << x.hours () << C ('H'); } if (x.minutes () != 0) { os << x.minutes () << C ('M'); } if (x.seconds () > 0.0) { std::ios_base::fmtflags ff ( os.setf (std::ios::fixed, std::ios::floatfield)); os << x.seconds () << C ('S'); os.setf (ff, std::ios::floatfield); } return os; } } } }