| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_COMMON_TIME_FORMAT_H_ | 5 #ifndef CHROME_COMMON_TIME_FORMAT_H_ |
| 6 #define CHROME_COMMON_TIME_FORMAT_H_ | 6 #define CHROME_COMMON_TIME_FORMAT_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 class Time; | 12 class Time; |
| 13 class TimeDelta; | 13 class TimeDelta; |
| 14 } | 14 } |
| 15 | 15 |
| 16 // Methods to format time values as strings. | 16 // Methods to format time values as strings. |
| 17 class TimeFormat { | 17 class TimeFormat { |
| 18 public: | 18 public: |
| 19 // TimeElapsed, TimeRemaining and TimeRemainingShort functions: | 19 // TimeElapsed, TimeRemaining and TimeRemainingShort functions: |
| 20 // These functions return a localized string of approximate time duration. The | 20 // These functions return a localized string of approximate time duration. The |
| 21 // conditions are simpler than PastTime since these functions are used for | 21 // conditions are simpler than PastTime since these functions are used for |
| 22 // in-progress operations and users have different expectations of units. | 22 // in-progress operations and users have different expectations of units. |
| 23 | 23 |
| 24 // Returns times in elapsed-format: "3 mins ago", "2 days ago". | 24 // Returns times in elapsed-format: "3 mins ago", "2 days ago". |
| 25 static string16 TimeElapsed(const base::TimeDelta& delta); | 25 static string16 TimeElapsed(const base::TimeDelta& delta); |
| 26 | 26 |
| 27 // Returns times in remaining-format: "3 mins left", "2 days left". | 27 // Returns times in remaining-format: "3 mins left", "2 days left". |
| 28 static string16 TimeRemaining(const base::TimeDelta& delta); | 28 static string16 TimeRemaining(const base::TimeDelta& delta); |
| 29 | 29 |
| 30 // Returns times in remaining-long-format: "3 minutes left", "2 days left". |
| 31 // Currently, this only affects the minutes in long format, the rest |
| 32 // of the time units are formatted the same as TimeRemaining does. |
| 33 static string16 TimeRemainingLong(const base::TimeDelta& delta); |
| 34 |
| 30 // Returns times in short-format: "3 mins", "2 days". | 35 // Returns times in short-format: "3 mins", "2 days". |
| 31 static string16 TimeRemainingShort(const base::TimeDelta& delta); | 36 static string16 TimeRemainingShort(const base::TimeDelta& delta); |
| 32 | 37 |
| 33 // For displaying a relative time in the past. This method returns either | 38 // For displaying a relative time in the past. This method returns either |
| 34 // "Today", "Yesterday", or an empty string if it's older than that. Returns | 39 // "Today", "Yesterday", or an empty string if it's older than that. Returns |
| 35 // the empty string for days in the future. | 40 // the empty string for days in the future. |
| 36 // | 41 // |
| 37 // TODO(brettw): This should be able to handle days in the future like | 42 // TODO(brettw): This should be able to handle days in the future like |
| 38 // "Tomorrow". | 43 // "Tomorrow". |
| 39 // TODO(tc): This should be able to do things like "Last week". This | 44 // TODO(tc): This should be able to do things like "Last week". This |
| 40 // requires handling singluar/plural for all languages. | 45 // requires handling singluar/plural for all languages. |
| 41 // | 46 // |
| 42 // The second parameter is optional, it is midnight of "Now" for relative day | 47 // The second parameter is optional, it is midnight of "Now" for relative day |
| 43 // computations: Time::Now().LocalMidnight() | 48 // computations: Time::Now().LocalMidnight() |
| 44 // If NULL, the current day's midnight will be retrieved, which can be | 49 // If NULL, the current day's midnight will be retrieved, which can be |
| 45 // slow. If many items are being processed, it is best to get the current | 50 // slow. If many items are being processed, it is best to get the current |
| 46 // time once at the beginning and pass it for each computation. | 51 // time once at the beginning and pass it for each computation. |
| 47 static string16 RelativeDate(const base::Time& time, | 52 static string16 RelativeDate(const base::Time& time, |
| 48 const base::Time* optional_midnight_today); | 53 const base::Time* optional_midnight_today); |
| 49 | 54 |
| 50 private: | 55 private: |
| 51 DISALLOW_IMPLICIT_CONSTRUCTORS(TimeFormat); | 56 DISALLOW_IMPLICIT_CONSTRUCTORS(TimeFormat); |
| 52 }; | 57 }; |
| 53 | 58 |
| 54 #endif // CHROME_COMMON_TIME_FORMAT_H_ | 59 #endif // CHROME_COMMON_TIME_FORMAT_H_ |
| OLD | NEW |