time_util.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef GOOGLE_APIS_COMMON_TIME_UTIL_H_
  5. #define GOOGLE_APIS_COMMON_TIME_UTIL_H_
  6. #include <string>
  7. #include "base/strings/string_piece.h"
  8. namespace base {
  9. class Time;
  10. } // namespace base
  11. namespace google_apis {
  12. namespace util {
  13. // Parses an RFC 3339 date/time into a base::Time, returning true on success.
  14. // The time string must be in the format "yyyy-mm-ddThh:mm:ss.dddTZ" (TZ is
  15. // either '+hh:mm', '-hh:mm', 'Z' (representing UTC), or an empty string).
  16. bool GetTimeFromString(base::StringPiece raw_value, base::Time* time);
  17. // Parses a date string of format "yyyy-mm-dd," returning true on success. The
  18. // time part of `time` is 00:00 (midnight) UTC.
  19. bool GetDateOnlyFromString(base::StringPiece raw_value, base::Time* time);
  20. // Formats a base::Time as an RFC 3339 date/time (in UTC).
  21. // If |time| is null, returns "null".
  22. std::string FormatTimeAsString(const base::Time& time);
  23. // Formats a base::Time as an RFC 3339 date/time (in localtime).
  24. // If |time| is null, returns "null".
  25. std::string FormatTimeAsStringLocaltime(const base::Time& time);
  26. } // namespace util
  27. } // namespace google_apis
  28. #endif // GOOGLE_APIS_COMMON_TIME_UTIL_H_