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

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

Issue 2022913002: Revert of Add: check exploded time is properly converted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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') | no next file with comments »
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #ifndef BASE_TIME_TIME_H_ 49 #ifndef BASE_TIME_TIME_H_
50 #define BASE_TIME_TIME_H_ 50 #define BASE_TIME_TIME_H_
51 51
52 #include <stdint.h> 52 #include <stdint.h>
53 #include <time.h> 53 #include <time.h>
54 54
55 #include <iosfwd> 55 #include <iosfwd>
56 #include <limits> 56 #include <limits>
57 57
58 #include "base/base_export.h" 58 #include "base/base_export.h"
59 #include "base/compiler_specific.h"
60 #include "base/numerics/safe_math.h" 59 #include "base/numerics/safe_math.h"
61 #include "build/build_config.h" 60 #include "build/build_config.h"
62 61
63 #if defined(OS_MACOSX) 62 #if defined(OS_MACOSX)
64 #include <CoreFoundation/CoreFoundation.h> 63 #include <CoreFoundation/CoreFoundation.h>
65 // Avoid Mac system header macro leak. 64 // Avoid Mac system header macro leak.
66 #undef TYPE_BOOL 65 #undef TYPE_BOOL
67 #endif 66 #endif
68 67
69 #if defined(OS_POSIX) 68 #if defined(OS_POSIX)
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 static bool ActivateHighResolutionTimer(bool activate); 512 static bool ActivateHighResolutionTimer(bool activate);
514 513
515 // Returns true if the high resolution timer is both enabled and activated. 514 // Returns true if the high resolution timer is both enabled and activated.
516 // This is provided for testing only, and is not tracked in a thread-safe 515 // This is provided for testing only, and is not tracked in a thread-safe
517 // way. 516 // way.
518 static bool IsHighResolutionTimerInUse(); 517 static bool IsHighResolutionTimerInUse();
519 #endif 518 #endif
520 519
521 // Converts an exploded structure representing either the local time or UTC 520 // Converts an exploded structure representing either the local time or UTC
522 // into a Time class. 521 // into a Time class.
523 // TODO(maksims): Get rid of these in favor of the methods below when
524 // all the callers stop using these ones.
525 static Time FromUTCExploded(const Exploded& exploded) { 522 static Time FromUTCExploded(const Exploded& exploded) {
526 base::Time time; 523 return FromExploded(false, exploded);
527 ignore_result(FromUTCExploded(exploded, &time));
528 return time;
529 } 524 }
530 static Time FromLocalExploded(const Exploded& exploded) { 525 static Time FromLocalExploded(const Exploded& exploded) {
531 base::Time time; 526 return FromExploded(true, exploded);
532 ignore_result(FromLocalExploded(exploded, &time));
533 return time;
534 }
535
536 // Converts an exploded structure representing either the local time or UTC
537 // into a Time class. Returns false on a failure when, for example, a day of
538 // month is set to 31 on a 28-30 day month.
539 static bool FromUTCExploded(const Exploded& exploded,
540 Time* time) WARN_UNUSED_RESULT {
541 return FromExploded(false, exploded, time);
542 }
543 static bool FromLocalExploded(const Exploded& exploded,
544 Time* time) WARN_UNUSED_RESULT {
545 return FromExploded(true, exploded, time);
546 } 527 }
547 528
548 // Converts a string representation of time to a Time object. 529 // Converts a string representation of time to a Time object.
549 // An example of a time string which is converted is as below:- 530 // An example of a time string which is converted is as below:-
550 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified 531 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified
551 // in the input string, FromString assumes local time and FromUTCString 532 // in the input string, FromString assumes local time and FromUTCString
552 // assumes UTC. A timezone that cannot be parsed (e.g. "UTC" which is not 533 // assumes UTC. A timezone that cannot be parsed (e.g. "UTC" which is not
553 // specified in RFC822) is treated as if the timezone is not specified. 534 // specified in RFC822) is treated as if the timezone is not specified.
554 // TODO(iyengar) Move the FromString/FromTimeT/ToTimeT/FromFileTime to 535 // TODO(iyengar) Move the FromString/FromTimeT/ToTimeT/FromFileTime to
555 // a new time converter class. 536 // a new time converter class.
(...skipping 20 matching lines...) Expand all
576 private: 557 private:
577 friend class time_internal::TimeBase<Time>; 558 friend class time_internal::TimeBase<Time>;
578 559
579 explicit Time(int64_t us) : TimeBase(us) {} 560 explicit Time(int64_t us) : TimeBase(us) {}
580 561
581 // Explodes the given time to either local time |is_local = true| or UTC 562 // Explodes the given time to either local time |is_local = true| or UTC
582 // |is_local = false|. 563 // |is_local = false|.
583 void Explode(bool is_local, Exploded* exploded) const; 564 void Explode(bool is_local, Exploded* exploded) const;
584 565
585 // Unexplodes a given time assuming the source is either local time 566 // Unexplodes a given time assuming the source is either local time
586 // |is_local = true| or UTC |is_local = false|. Function returns false on 567 // |is_local = true| or UTC |is_local = false|.
587 // failure and sets |time| to Time(0). Otherwise returns true and sets |time| 568 static Time FromExploded(bool is_local, const Exploded& exploded);
588 // to non-exploded time.
589 static bool FromExploded(bool is_local,
590 const Exploded& exploded,
591 Time* time) WARN_UNUSED_RESULT;
592 569
593 // Converts a string representation of time to a Time object. 570 // Converts a string representation of time to a Time object.
594 // An example of a time string which is converted is as below:- 571 // An example of a time string which is converted is as below:-
595 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified 572 // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified
596 // in the input string, local time |is_local = true| or 573 // in the input string, local time |is_local = true| or
597 // UTC |is_local = false| is assumed. A timezone that cannot be parsed 574 // UTC |is_local = false| is assumed. A timezone that cannot be parsed
598 // (e.g. "UTC" which is not specified in RFC822) is treated as if the 575 // (e.g. "UTC" which is not specified in RFC822) is treated as if the
599 // timezone is not specified. 576 // timezone is not specified.
600 static bool FromStringInternal(const char* time_string, 577 static bool FromStringInternal(const char* time_string,
601 bool is_local, 578 bool is_local,
602 Time* parsed_time); 579 Time* parsed_time);
603
604 // Comparison does not consider |day_of_week| when doing the operation.
605 static bool ExplodedMostlyEquals(const Exploded& lhs, const Exploded& rhs);
606 }; 580 };
607 581
608 // static 582 // static
609 constexpr TimeDelta TimeDelta::FromDays(int days) { 583 constexpr TimeDelta TimeDelta::FromDays(int days) {
610 return days == std::numeric_limits<int>::max() 584 return days == std::numeric_limits<int>::max()
611 ? Max() 585 ? Max()
612 : TimeDelta(days * Time::kMicrosecondsPerDay); 586 : TimeDelta(days * Time::kMicrosecondsPerDay);
613 } 587 }
614 588
615 // static 589 // static
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 static void WaitUntilInitializedWin(); 789 static void WaitUntilInitializedWin();
816 #endif 790 #endif
817 }; 791 };
818 792
819 // For logging use only. 793 // For logging use only.
820 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); 794 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks);
821 795
822 } // namespace base 796 } // namespace base
823 797
824 #endif // BASE_TIME_TIME_H_ 798 #endif // BASE_TIME_TIME_H_
OLDNEW
« no previous file with comments | « no previous file | base/time/time.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698