Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: third_party/protobuf/src/google/protobuf/util/time_util.cc

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // give -3 as the result with the remainder being 1. This function ensures 135 // give -3 as the result with the remainder being 1. This function ensures
136 // we always return -2 (closer to zero) regardless of the implementation. 136 // we always return -2 (closer to zero) regardless of the implementation.
137 if (result < 0 && remainder > 0) { 137 if (result < 0 && remainder > 0) {
138 return result + 1; 138 return result + 1;
139 } else { 139 } else {
140 return result; 140 return result;
141 } 141 }
142 } 142 }
143 } // namespace 143 } // namespace
144 144
145 // Actually define these static const integers. Required by C++ standard (but
146 // some compilers don't like it).
147 #ifndef _MSC_VER
148 const int64 TimeUtil::kTimestampMinSeconds;
149 const int64 TimeUtil::kTimestampMaxSeconds;
150 const int64 TimeUtil::kDurationMaxSeconds;
151 const int64 TimeUtil::kDurationMinSeconds;
152 #endif // !_MSC_VER
153
145 string TimeUtil::ToString(const Timestamp& timestamp) { 154 string TimeUtil::ToString(const Timestamp& timestamp) {
146 return FormatTime(timestamp.seconds(), timestamp.nanos()); 155 return FormatTime(timestamp.seconds(), timestamp.nanos());
147 } 156 }
148 157
149 bool TimeUtil::FromString(const string& value, Timestamp* timestamp) { 158 bool TimeUtil::FromString(const string& value, Timestamp* timestamp) {
150 int64 seconds; 159 int64 seconds;
151 int32 nanos; 160 int32 nanos;
152 if (!ParseTime(value, &seconds, &nanos)) { 161 if (!ParseTime(value, &seconds, &nanos)) {
153 return false; 162 return false;
154 } 163 }
(...skipping 12 matching lines...) Expand all
167 176
168 string TimeUtil::ToString(const Duration& duration) { 177 string TimeUtil::ToString(const Duration& duration) {
169 string result; 178 string result;
170 int64 seconds = duration.seconds(); 179 int64 seconds = duration.seconds();
171 int32 nanos = duration.nanos(); 180 int32 nanos = duration.nanos();
172 if (seconds < 0 || nanos < 0) { 181 if (seconds < 0 || nanos < 0) {
173 result += "-"; 182 result += "-";
174 seconds = -seconds; 183 seconds = -seconds;
175 nanos = -nanos; 184 nanos = -nanos;
176 } 185 }
177 result += StringPrintf("%" GOOGLE_LL_FORMAT "d", seconds); 186 result += SimpleItoa(seconds);
178 if (nanos != 0) { 187 if (nanos != 0) {
179 result += "." + FormatNanos(nanos); 188 result += "." + FormatNanos(nanos);
180 } 189 }
181 result += "s"; 190 result += "s";
182 return result; 191 return result;
183 } 192 }
184 193
185 static int64 Pow(int64 x, int y) { 194 static int64 Pow(int64 x, int y) {
186 int64 result = 1; 195 int64 result = 1;
187 for (int i = 0; i < y; ++i) { 196 for (int i = 0; i < y; ++i) {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 return t; 525 return t;
517 } 526 }
518 527
519 Duration operator-(const Timestamp& t1, const Timestamp& t2) { 528 Duration operator-(const Timestamp& t1, const Timestamp& t2) {
520 return CreateNormalized<Duration>(t1.seconds() - t2.seconds(), 529 return CreateNormalized<Duration>(t1.seconds() - t2.seconds(),
521 t1.nanos() - t2.nanos()); 530 t1.nanos() - t2.nanos());
522 } 531 }
523 } // namespace protobuf 532 } // namespace protobuf
524 533
525 } // namespace google 534 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698