MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ParseRfc3339Time

Function ParseRfc3339Time

tensorflow/core/platform/cloud/time_util.cc:35–54  ·  view source on GitHub ↗

Only implements one special case of RFC 3339 which is returned by GCS API, e.g 2016-04-29T23:15:24.896Z.

Source from the content-addressed store, hash-verified

33// Only implements one special case of RFC 3339 which is returned by
34// GCS API, e.g 2016-04-29T23:15:24.896Z.
35Status ParseRfc3339Time(const string& time, int64* mtime_nsec) {
36 tm parsed{0};
37 float seconds;
38 if (sscanf(time.c_str(), "%4d-%2d-%2dT%2d:%2d:%fZ", &(parsed.tm_year),
39 &(parsed.tm_mon), &(parsed.tm_mday), &(parsed.tm_hour),
40 &(parsed.tm_min), &seconds) != 6) {
41 return errors::Internal(
42 strings::StrCat("Unrecognized RFC 3339 time format: ", time));
43 }
44 const int int_seconds = std::floor(seconds);
45 parsed.tm_year -= 1900; // tm_year expects years since 1900.
46 parsed.tm_mon -= 1; // month is zero-based.
47 parsed.tm_sec = int_seconds;
48
49 *mtime_nsec = timegm(&parsed) * kNanosecondsPerSecond +
50 static_cast<int64>(std::floor((seconds - int_seconds) *
51 kNanosecondsPerSecond));
52
53 return Status::OK();
54}
55
56} // namespace tensorflow

Callers 2

TESTFunction · 0.85
UncachedStatForObjectMethod · 0.85

Calls 4

InternalFunction · 0.85
floorClass · 0.85
c_strMethod · 0.80
StrCatFunction · 0.50

Tested by 1

TESTFunction · 0.68