Apply timezone-based time info to file attribute 78/14078/1
authorHyunbin Lee <hyunbin.lee@samsung.com>
Tue, 3 Dec 2013 06:41:03 +0000 (15:41 +0900)
committerHyunbin Lee <hyunbin.lee@samsung.com>
Mon, 23 Dec 2013 06:33:13 +0000 (15:33 +0900)
Change-Id: I7c2f40076f198d0dffb4792bc9ac4bdae17bf644
Signed-off-by: Hyunbin Lee <hyunbin.lee@samsung.com>
src/io/FIo_DirEnumeratorImpl.cpp
src/io/FIo_FileUtil.cpp

index d3ce322..6592188 100644 (file)
 #include <limits.h>
 #include <unique_ptr.h>
 
-#include <FBaseDateTime.h>
 #include <FIoDirEntry.h>
 #include <FIoDirEnumerator.h>
+#include <FBaseDateTime.h>
 #include <FBaseSysLog.h>
+#include <FLclLocaleManager.h>
+#include <FLclTimeZone.h>
 
 #include <FBase_NativeError.h>
 #include <FBase_StringConverter.h>
@@ -39,6 +41,7 @@
 
 using namespace std;
 using namespace Tizen::Base;
+using namespace Tizen::Locales;
 
 namespace Tizen { namespace Io
 {
@@ -160,12 +163,18 @@ _DirEnumeratorImpl::MoveNext(void)
                        "Failed to get attributes for directory entry (%s), errno: %d (%s)", pEntryPath.get(), errno, strerror(errno));
 
        struct tm resultTm;
-       struct tm* pTm = localtime_r(&statbuf.st_mtime, &resultTm);
+       struct tm* pTm = gmtime_r(&statbuf.st_mtime, &resultTm);
        SysTryReturnResult(NID_IO, pTm != null, E_SYSTEM, "Failed to get local time (%s).", strerror(errno));
 
        DateTime dateTime;
        r = dateTime.SetValue(_BASE_YEAR + pTm->tm_year, 1 + pTm->tm_mon, pTm->tm_mday, pTm->tm_hour, pTm->tm_min, pTm->tm_sec);
-       SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+       SysTryReturn(NID_IO, !IsFailed(r), E_SYSTEM, r, "[%s] Propagating to caller...", GetErrorMessage(r));
+
+       LocaleManager locMgr;
+       locMgr.Construct();
+
+       TimeZone tmZone = locMgr.GetSystemTimeZone();
+       DateTime locDateTime = tmZone.UtcTimeToWallTime(dateTime);
 
        if (__pCurDirEntry == null)
        {
@@ -181,7 +190,7 @@ _DirEnumeratorImpl::MoveNext(void)
                hidden = true;
        }
 
-       _DirEntryImpl::GetInstance(__pCurDirEntry)->Set(dateTime, statbuf.st_size, String(pDirEnt->d_name),
+       _DirEntryImpl::GetInstance(__pCurDirEntry)->Set(locDateTime, statbuf.st_size, String(pDirEnt->d_name),
                        S_ISDIR(statbuf.st_mode), (statbuf.st_mode & S_IWUSR) ? false : true, hidden);
 
        return E_SUCCESS;
index 0edf5d5..439b81b 100644 (file)
@@ -36,6 +36,8 @@
 #include <FIoDirectory.h>
 #include <FBaseResult.h>
 #include <FBaseSysLog.h>
+#include <FLclLocaleManager.h>
+#include <FLclTimeZone.h>
 
 #include <FBase_StringConverter.h>
 #include <FBase_NativeError.h>
@@ -47,6 +49,7 @@
 
 using namespace std;
 using namespace Tizen::Base;
+using namespace Tizen::Locales;
 using namespace Tizen::App;
 
 namespace Tizen { namespace Io
@@ -344,14 +347,21 @@ _FileUtil::GetAttributes(const String& filePath, FileAttributes& attribute)
        attr = statbuf.st_mode;
 
        struct tm resultTm;
-       struct tm* pTm = localtime_r(&statbuf.st_mtime, &resultTm);
+       struct tm* pTm = gmtime_r(&statbuf.st_mtime, &resultTm);
        SysTryReturnResult(NID_IO, pTm != null, E_SYSTEM, "Failed to get local time (%s).", strerror(errno));
 
        r = dateTime.SetValue(_BASE_YEAR + pTm->tm_year, 1 + pTm->tm_mon, pTm->tm_mday, pTm->tm_hour, pTm->tm_min, pTm->tm_sec);
-       SysTryReturn(NID_IO, (!IsFailed(r)), r, r, "[%s] Failed to set DateTime.", GetErrorMessage(r));
+       SysTryReturn(NID_IO, !IsFailed(r), E_SYSTEM, r, "[%s] Failed to set DateTime.", GetErrorMessage(r));
 
        r = modifiedTime.SetValue(_BASE_YEAR + pTm->tm_year, 1 + pTm->tm_mon, pTm->tm_mday, pTm->tm_hour, pTm->tm_min, pTm->tm_sec);
-       SysTryReturn(NID_IO, (!IsFailed(r)), r, r, "[%s] Failed to set DateTime.", GetErrorMessage(r));
+       SysTryReturn(NID_IO, !IsFailed(r), E_SYSTEM, r, "[%s] Failed to set DateTime.", GetErrorMessage(r));
+
+       LocaleManager locMgr;
+       locMgr.Construct();
+
+       TimeZone tmZone = locMgr.GetSystemTimeZone();
+       DateTime locDateTime = tmZone.UtcTimeToWallTime(dateTime);
+       DateTime locModifiedTime = tmZone.UtcTimeToWallTime(modifiedTime);
 
        fileName = _FileUtil::GetFileName(filePath);
        if (fileName.StartsWith(L".", 0)) // including . and ..
@@ -359,7 +369,7 @@ _FileUtil::GetAttributes(const String& filePath, FileAttributes& attribute)
                hidden = true;
        }
 
-       _FileAttributesImpl::GetInstance(attribute)->Set(dateTime, modifiedTime, fileSize, attr, hidden);
+       _FileAttributesImpl::GetInstance(attribute)->Set(locDateTime, locModifiedTime, fileSize, attr, hidden);
 
        return E_SUCCESS;
 }