Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added private methods to helper. Refs #9186.
- These will be used in methods that write data to workspaces from catalog responses.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,39 @@ | ||
#include "MantidICat/CatalogHelper.h" | ||
#include "MantidKernel/DateAndTime.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace ICat | ||
{ | ||
/** | ||
* Convert a file size to human readable file format. | ||
* @param fileSize :: The size in bytes of the file. | ||
*/ | ||
std::string CatalogHelper::bytesToString(int64_t &fileSize) | ||
{ | ||
const char* args[] = {"B", "KB", "MB", "GB"}; | ||
std::vector<std::string> units(args, args + 4); | ||
|
||
unsigned order = 0; | ||
|
||
while (fileSize >= 1024 && order + 1 < units.size()) | ||
{ | ||
order++; | ||
fileSize = fileSize / 1024; | ||
} | ||
|
||
return boost::lexical_cast<std::string>(fileSize) + units.at(order); | ||
} | ||
|
||
/** | ||
* Formats a given timestamp to human readable datetime. | ||
* @param timestamp :: Unix timestamp. | ||
* @param format :: The desired format to output. | ||
* @return string :: Formatted Unix timestamp. | ||
*/ | ||
std::string CatalogHelper::formatDateTime(const time_t ×tamp, const std::string &format) | ||
{ | ||
return Kernel::DateAndTime(boost::posix_time::from_time_t(timestamp)).toFormattedString(format); | ||
} | ||
} | ||
} |