home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / classsrc.pak / TIMEIO.CPP < prev    next >
C/C++ Source or Header  |  1997-07-23  |  3KB  |  89 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  TIMEIO.CPP                                                            */
  4. /*                                                                        */
  5. /*  Copyright (c) 1993, 1994 Borland International                        */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __STDIO_H )
  11. #include <stdio.h>
  12. #endif
  13.  
  14. #if !defined( __STRSTREA_H )
  15. #include <strstrea.h>
  16. #endif
  17.  
  18. #if !defined( __IOMANIP_H )
  19. #include <iomanip.h>
  20. #endif
  21.  
  22. #if !defined( __CSTRING_H )
  23. #include <cstring.h>
  24. #endif
  25.  
  26. #if !defined( CLASSLIB_TIME_H )
  27. #include <classlib/time.h>
  28. #endif
  29.  
  30. #if !defined( CLASSLIB_FILE_H )
  31. #include <classlib/file.h>
  32. #endif
  33.  
  34. // Static variable intialization:
  35. int TTime::PrintDateFlag = 1;
  36.  
  37. string TTime::AsString() const
  38. {
  39.     char buf[80];
  40.     ostrstream strtemp(buf, sizeof(buf));
  41.     strtemp << (*this) << ends;
  42.     string temp(buf);
  43.     return temp;
  44. }
  45.  
  46. ostream _BIDSFAR & _BIDSFUNC operator << ( ostream _BIDSFAR & s, const TTime _BIDSFAR & t )
  47. {
  48.     char buf[80];
  49.  
  50.     // We use an ostrstream to format into buf so that
  51.     // we don't affect the ostream's width setting.
  52.     ostrstream out( buf, sizeof(buf) );
  53.   
  54.     // First print the date if requested:
  55.     if(TTime::PrintDateFlag) 
  56.         out << TDate(t) << " ";
  57.  
  58.     unsigned hh = t.Hour();
  59.     out << (hh <= 12 ? hh : hh-12) << ':' 
  60.         << setfill('0') << setw(2) << t.Minute() << ':'
  61.         << setw(2) << t.Second() << ' ' << setfill(' ');
  62.     out << ( hh<12 ? "am" : "pm") << ends;
  63.  
  64.     // now we write out the formatted buffer, and the ostream's
  65.     // width setting will control the actual width of the field.
  66.     s << buf;
  67.     return s;
  68. }
  69.  
  70. int TTime::PrintDate( int f )
  71. {
  72.     int temp = PrintDateFlag;
  73.     PrintDateFlag = f;
  74.     return temp;
  75. }
  76.  
  77. ostream _BIDSFAR & _BIDSFUNC operator << ( ostream _BIDSFAR & os, const TFileStatus _BIDSFAR & status )
  78. {
  79.     os << "File Status: " << status.fullName << '\n';
  80.     os << "    created: " << status.createTime << '\n';
  81.     os << "   modified: " << status.modifyTime << '\n';
  82.     os << "   accessed: " << status.accessTime << '\n';
  83.     os << "       size: " << status.size << '\n';
  84.     os << " attributes: " << (int)status.attribute << '\n';
  85.     return os;
  86. }
  87.  
  88.  
  89.