Only implements one special case of RFC 3339 which is returned by GCS API, e.g 2016-04-29T23:15:24.896Z.
| 33 | // Only implements one special case of RFC 3339 which is returned by |
| 34 | // GCS API, e.g 2016-04-29T23:15:24.896Z. |
| 35 | Status 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 |