X Tutup
/* * Copyright (C) 2012 Yee Young Han (http://blog.naver.com/websearch) * * 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "SipPlatformDefine.h" #include #include "TimeString.h" #include "StringUtility.h" #include "MemoryDebug.h" /** * @ingroup SipPlatform * @brief ÇöÀç ½Ã°£À» ³â,¿ù,ÀÏ,½Ã,ºÐ,ÃÊ ±¸Á¶Ã¼¿¡ ÀúÀåÇÑ´Ù. * @param iTime ÇöÀç ½Ã°£ * @param sttTm ³â,¿ù,ÀÏ,½Ã,ºÐ,ÃÊ ±¸Á¶Ã¼ */ void LocalTime( time_t iTime, struct tm & sttTm ) { #ifdef WIN32 localtime_s( &sttTm, &iTime ); #else localtime_r( &iTime, &sttTm ); #endif } /** * @ingroup SipPlatform * @brief ½Ã°£ º¯¼ö¸¦ ½Ã°£ ¹®ÀÚ¿­ º¯¼ö¿¡ ÀúÀåÇÑ´Ù. * @param iTime ½Ã°£ º¯¼ö * @param pszTime ½Ã°£ ¹®ÀÚ¿­ÀÌ ÀúÀåµÉ º¯¼ö * @param iTimeSize pszTime º¯¼öÀÇ Å©±â */ void GetDateTimeString( time_t iTime, char * pszTime, int iTimeSize ) { struct tm sttTm; LocalTime( iTime, sttTm ); snprintf( pszTime, iTimeSize, "%04d%02d%02d%02d%02d%02d", sttTm.tm_year + 1900, sttTm.tm_mon + 1, sttTm.tm_mday , sttTm.tm_hour, sttTm.tm_min, sttTm.tm_sec ); } /** * @ingroup SipPlatform * @brief ³â¿ùÀϽúÐÃÊ ¹®ÀÚ¿­À» ÀúÀåÇÑ´Ù. * @param pszTime ³â¿ùÀϽúÐÃÊ ¹®ÀÚ¿­ ÀúÀå º¯¼ö * @param iTimeSize pszTime º¯¼öÀÇ Å©±â */ void GetDateTimeString( char * pszTime, int iTimeSize ) { time_t iTime; time( &iTime ); GetDateTimeString( iTime, pszTime, iTimeSize ); } /** * @ingroup SipPlatform * @brief ³â¿ùÀÏ ¹®ÀÚ¿­À» ÀúÀåÇÑ´Ù. * @param iTime ½Ã°£ * @param pszDate ³â¿ùÀÏ ¹®ÀÚ¿­À» ÀúÀå º¯¼ö * @param iDateSize pszDate º¯¼öÀÇ Å©±â */ void GetDateString( time_t iTime, char * pszDate, int iDateSize ) { struct tm sttTm; LocalTime( iTime, sttTm ); snprintf( pszDate, iDateSize, "%04d%02d%02d", sttTm.tm_year + 1900, sttTm.tm_mon + 1, sttTm.tm_mday ); } /** * @ingroup SipPlatform * @brief ³â¿ùÀÏ ¹®ÀÚ¿­À» ÀúÀåÇÑ´Ù. * @param pszDate ³â¿ùÀÏ ¹®ÀÚ¿­À» ÀúÀå º¯¼ö * @param iDateSize pszDate º¯¼öÀÇ Å©±â */ void GetDateString( char * pszDate, int iDateSize ) { time_t iTime; time( &iTime ); GetDateString( iTime, pszDate, iDateSize ); } /** * @ingroup SipPlatform * @brief ½ÃºÐÃÊ ¹®ÀÚ¿­À» ÀúÀåÇÑ´Ù. * @param iTime ½Ã°£ * @param pszTime ½ÃºÐÃÊ ¹®ÀÚ¿­ ÀúÀå º¯¼ö * @param iTimeSize pszTime º¯¼öÀÇ Å©±â */ void GetTimeString( time_t iTime, char * pszTime, int iTimeSize ) { struct tm sttTm; LocalTime( iTime, sttTm ); snprintf( pszTime, iTimeSize, "%02d%02d%02d", sttTm.tm_hour, sttTm.tm_min, sttTm.tm_sec ); } /** * @ingroup SipPlatform * @brief ½ÃºÐÃÊ ¹®ÀÚ¿­À» ÀúÀåÇÑ´Ù. * @param pszTime ½ÃºÐÃÊ ¹®ÀÚ¿­ ÀúÀå º¯¼ö * @param iTimeSize pszTime º¯¼öÀÇ Å©±â */ void GetTimeString( char * pszTime, int iTimeSize ) { time_t iTime; time( &iTime ); GetTimeString( iTime, pszTime, iTimeSize ); } /** * @ingroup SipPlatform * @brief ³â¿ùÀϽúÐÃÊ ¹®ÀÚ¿­À» time_t ·Î º¯È¯ÇÑ´Ù. * @param pszTime ³â¿ùÀϽúÐÃÊ ¹®ÀÚ¿­ * @returns ¼º°øÇϸé time_t °ªÀÌ ¸®ÅÏµÇ°í ½ÇÆÐÇϸé 0 ÀÌ ¸®ÅϵȴÙ. */ time_t ParseDateTimeString( const char * pszTime ) { struct tm sttTm; int iLen = (int)strlen( pszTime ); if( iLen < 14 ) return 0; memset( &sttTm, 0, sizeof(sttTm) ); sttTm.tm_year = GetInt( pszTime, 4 ) - 1900; sttTm.tm_mon = GetInt( pszTime+4, 2 ) - 1; sttTm.tm_mday = GetInt( pszTime+6, 2 ); sttTm.tm_hour = GetInt( pszTime+8, 2 ); sttTm.tm_min = GetInt( pszTime+10, 2 ); sttTm.tm_sec = GetInt( pszTime+12, 2 ); return mktime( &sttTm ); }
X Tutup