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

Side by Side Diff: base/time/time.h

Issue 1988663002: Add: check exploded time is properly converted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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
« no previous file with comments | « no previous file | base/time/time.cc » ('j') | base/time/time_mac.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Time represents an absolute point in coordinated universal time (UTC), 5 // Time represents an absolute point in coordinated universal time (UTC),
6 // internally represented as microseconds (s/1,000,000) since the Windows epoch 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch
7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are 7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are
8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump 8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump
9 // around as the operating system makes adjustments to synchronize (e.g., with 9 // around as the operating system makes adjustments to synchronize (e.g., with
10 // NTP servers). Thus, client code that uses the Time class must account for 10 // NTP servers). Thus, client code that uses the Time class must account for
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 int hour; // Hour within the current day (0-23) 413 int hour; // Hour within the current day (0-23)
414 int minute; // Minute within the current hour (0-59) 414 int minute; // Minute within the current hour (0-59)
415 int second; // Second within the current minute (0-59 plus leap 415 int second; // Second within the current minute (0-59 plus leap
416 // seconds which may take it up to 60). 416 // seconds which may take it up to 60).
417 int millisecond; // Milliseconds within the current second (0-999) 417 int millisecond; // Milliseconds within the current second (0-999)
418 418
419 // A cursory test for whether the data members are within their 419 // A cursory test for whether the data members are within their
420 // respective ranges. A 'true' return value does not guarantee the 420 // respective ranges. A 'true' return value does not guarantee the
421 // Exploded value can be successfully converted to a Time value. 421 // Exploded value can be successfully converted to a Time value.
422 bool HasValidValues() const; 422 bool HasValidValues() const;
423 bool operator!=(const Exploded& rhs);
423 }; 424 };
424 425
425 // Contains the NULL time. Use Time::Now() to get the current time. 426 // Contains the NULL time. Use Time::Now() to get the current time.
426 Time() : TimeBase(0) { 427 Time() : TimeBase(0) {
427 } 428 }
428 429
429 // Returns the time for epoch in Unix-like system (Jan 1, 1970). 430 // Returns the time for epoch in Unix-like system (Jan 1, 1970).
430 static Time UnixEpoch(); 431 static Time UnixEpoch();
431 432
432 // Returns the current time. Watch out, the system might adjust its clock 433 // Returns the current time. Watch out, the system might adjust its clock
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 516
516 // Converts an exploded structure representing either the local time or UTC 517 // Converts an exploded structure representing either the local time or UTC
517 // into a Time class. 518 // into a Time class.
518 static Time FromUTCExploded(const Exploded& exploded) { 519 static Time FromUTCExploded(const Exploded& exploded) {
519 return FromExploded(false, exploded); 520 return FromExploded(false, exploded);
520 } 521 }
521 static Time FromLocalExploded(const Exploded& exploded) { 522 static Time FromLocalExploded(const Exploded& exploded) {
522 return FromExploded(true, exploded); 523 return FromExploded(true, exploded);
523 } 524 }
524 525
526 // Converts an exploded structure representing either the local time or UTC
527 // into a Time class.
528 // This is a transition to a new format, where the converted time is set to
529 // |time| and FromUTCExploded, FromLocalExploded and FromExploded return true
530 // on success or false on failure. For example, FromExploded can fail when
531 // 31st of a month is set on a 28-30 day month, which results in 1st day of
532 // the next month.
533 static bool FromUTCExploded(const Exploded& exploded, Time& time) {
mmenke 2016/05/20 19:44:56 Per Google C++ style guide, non-const refs are for
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
534 return FromExploded(false, exploded, time);
535 }
536 static bool FromLocalExploded(const Exploded& exploded, Time& time) {
mmenke 2016/05/20 19:44:56 These two should use WARN_UNUSED_RESULT.
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
537 return FromExploded(true, exploded, time);
538 }
mmenke 2016/05/20 19:44:56 Is the plan to replace calls to the old methods wi
maksims (do not use this acc) 2016/05/24 09:14:21 Yes, I would like to do so.
539
525 // Converts a string representation of time to a Time object. 540 // Converts a string representation of time to a Time object.
526 // An example of a time string which is converted is as below:- 541 // An example of a time string which is converted is as below:-
527 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified 542 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified
528 // in the input string, FromString assumes local time and FromUTCString 543 // in the input string, FromString assumes local time and FromUTCString
529 // assumes UTC. A timezone that cannot be parsed (e.g. "UTC" which is not 544 // assumes UTC. A timezone that cannot be parsed (e.g. "UTC" which is not
530 // specified in RFC822) is treated as if the timezone is not specified. 545 // specified in RFC822) is treated as if the timezone is not specified.
531 // TODO(iyengar) Move the FromString/FromTimeT/ToTimeT/FromFileTime to 546 // TODO(iyengar) Move the FromString/FromTimeT/ToTimeT/FromFileTime to
532 // a new time converter class. 547 // a new time converter class.
533 static bool FromString(const char* time_string, Time* parsed_time) { 548 static bool FromString(const char* time_string, Time* parsed_time) {
534 return FromStringInternal(time_string, true, parsed_time); 549 return FromStringInternal(time_string, true, parsed_time);
(...skipping 19 matching lines...) Expand all
554 friend class time_internal::TimeBase<Time>; 569 friend class time_internal::TimeBase<Time>;
555 570
556 explicit Time(int64_t us) : TimeBase(us) {} 571 explicit Time(int64_t us) : TimeBase(us) {}
557 572
558 // Explodes the given time to either local time |is_local = true| or UTC 573 // Explodes the given time to either local time |is_local = true| or UTC
559 // |is_local = false|. 574 // |is_local = false|.
560 void Explode(bool is_local, Exploded* exploded) const; 575 void Explode(bool is_local, Exploded* exploded) const;
561 576
562 // Unexplodes a given time assuming the source is either local time 577 // Unexplodes a given time assuming the source is either local time
563 // |is_local = true| or UTC |is_local = false|. 578 // |is_local = true| or UTC |is_local = false|.
564 static Time FromExploded(bool is_local, const Exploded& exploded); 579 static Time FromExploded(bool is_local, const Exploded& exploded);
mmenke 2016/05/20 19:44:56 If we're going to keep the old methods around (Per
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
565 580
581 // Unexplodes a given time assuming the source is either local time
582 // |is_local = true| or UTC |is_local = false|.
583 // This is a transition to a newer form. Function returns false on failure
584 // and sets |time| to Time(0). Otherwise returns true and sets |time| to
585 // non-exploded time.
586 static bool FromExploded(bool is_local, const Exploded& exploded, Time& time);
mmenke 2016/05/20 19:44:56 WARN_UNUSED_RESULT
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
587
566 // Converts a string representation of time to a Time object. 588 // Converts a string representation of time to a Time object.
567 // An example of a time string which is converted is as below:- 589 // An example of a time string which is converted is as below:-
568 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified 590 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified
569 // in the input string, local time |is_local = true| or 591 // in the input string, local time |is_local = true| or
570 // UTC |is_local = false| is assumed. A timezone that cannot be parsed 592 // UTC |is_local = false| is assumed. A timezone that cannot be parsed
571 // (e.g. "UTC" which is not specified in RFC822) is treated as if the 593 // (e.g. "UTC" which is not specified in RFC822) is treated as if the
572 // timezone is not specified. 594 // timezone is not specified.
573 static bool FromStringInternal(const char* time_string, 595 static bool FromStringInternal(const char* time_string,
574 bool is_local, 596 bool is_local,
575 Time* parsed_time); 597 Time* parsed_time);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 static void WaitUntilInitializedWin(); 798 static void WaitUntilInitializedWin();
777 #endif 799 #endif
778 }; 800 };
779 801
780 // For logging use only. 802 // For logging use only.
781 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); 803 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks);
782 804
783 } // namespace base 805 } // namespace base
784 806
785 #endif // BASE_TIME_TIME_H_ 807 #endif // BASE_TIME_TIME_H_
OLDNEW
« no previous file with comments | « no previous file | base/time/time.cc » ('j') | base/time/time_mac.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698