diff options
author | Sascha Volkenandt <sascha (at) akv-soft (dot) de> | 2007-01-03 16:03:30 +0000 |
---|---|---|
committer | Sascha Volkenandt <sascha (at) akv-soft (dot) de> | 2007-01-03 16:03:30 +0000 |
commit | 9903d559f0f7b1bad0946e5791a457ffe33a0df5 (patch) | |
tree | 59ec4544c25e841f10fdfb9fb12313ec5ade4408 /tools.cpp | |
parent | 63cf033a92dd903e14cbf59570d1044b87be6d58 (diff) | |
download | vdr-plugin-live-9903d559f0f7b1bad0946e5791a457ffe33a0df5.tar.gz vdr-plugin-live-9903d559f0f7b1bad0946e5791a457ffe33a0df5.tar.bz2 |
- added function for datetime formatting
Diffstat (limited to 'tools.cpp')
-rw-r--r-- | tools.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tools.cpp b/tools.cpp new file mode 100644 index 0000000..3eda4b8 --- /dev/null +++ b/tools.cpp @@ -0,0 +1,27 @@ +#include <sstream> +#include <stdexcept> +#include "tools.h" + +namespace vdrlive { + +using namespace std; + +string FormatDateTime( char const* format, time_t time ) +{ + struct tm tm_r; + if ( localtime_r( &time, &tm_r ) == 0 ) { + ostringstream builder; + builder << "cannot represent timestamp " << time << " as local time"; + throw runtime_error( builder.str() ); + } + + char result[ 256 ]; + if ( strftime( result, sizeof( result ), format, &tm_r ) == 0 ) { + ostringstream builder; + builder << "representation of timestamp " << time << " exceeds " << sizeof( result ) << " bytes"; + throw runtime_error( builder.str() ); + } + return result; +} + +} |