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