Skip to content

Commit

Permalink
Added private methods to helper. Refs #9186.
Browse files Browse the repository at this point in the history
- These will be used in methods that write data to workspaces from catalog responses.
  • Loading branch information
jawrainey committed Apr 1, 2014
1 parent e362b0d commit 1130d8c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Code/Mantid/Framework/ICat/inc/MantidICat/CatalogHelper.h
Expand Up @@ -49,6 +49,12 @@ namespace Mantid

throw std::runtime_error(exception);
}

private:
// Convert a file size to human readable file format.
std::string bytesToString(int64_t &fileSize);
// Helper method that formats a given timestamp.
std::string formatDateTime(const time_t &timestamp, const std::string &format);
};
}
}
Expand Down
30 changes: 30 additions & 0 deletions Code/Mantid/Framework/ICat/src/CatalogHelper.cpp
@@ -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 &timestamp, const std::string &format)
{
return Kernel::DateAndTime(boost::posix_time::from_time_t(timestamp)).toFormattedString(format);
}
}
}

0 comments on commit 1130d8c

Please sign in to comment.