Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / base / l10n / time_format.h
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
5 #ifndef UI_BASE_L10N_TIME_FORMAT_H_
6 #define UI_BASE_L10N_TIME_FORMAT_H_
7
8 #include "base/basictypes.h"
9 #include "base/strings/string16.h"
10 #include "ui/base/ui_base_export.h"
11
12 namespace base {
13 class Time;
14 class TimeDelta;
15 }
16
17 namespace ui {
18
19 // Methods to format time values as strings.
20 class UI_BASE_EXPORT TimeFormat {
21  public:
22   // TimeElapsed, TimeRemaining* and TimeDuration*:
23   // These functions return a localized string of approximate time duration.
24
25   // Returns times in elapsed-format: "3 mins ago", "2 days ago".
26   static base::string16 TimeElapsed(const base::TimeDelta& delta);
27
28   // Returns times in remaining-format: "3 mins left", "2 days left".
29   static base::string16 TimeRemaining(const base::TimeDelta& delta);
30
31   // Returns times in remaining-long-format: "3 minutes left", "2 days left".
32   static base::string16 TimeRemainingLong(const base::TimeDelta& delta);
33
34   // Returns times in short-format: "3 mins", "2 days".
35   static base::string16 TimeDurationShort(const base::TimeDelta& delta);
36
37   // Return times in long-format: "2 hours", "25 minutes".
38   static base::string16 TimeDurationLong(const base::TimeDelta& delta);
39
40   // For displaying a relative time in the past.  This method returns either
41   // "Today", "Yesterday", or an empty string if it's older than that.  Returns
42   // the empty string for days in the future.
43   //
44   // TODO(brettw): This should be able to handle days in the future like
45   //    "Tomorrow".
46   // TODO(tc): This should be able to do things like "Last week".  This
47   //    requires handling singluar/plural for all languages.
48   //
49   // The second parameter is optional, it is midnight of "Now" for relative day
50   // computations: Time::Now().LocalMidnight()
51   // If NULL, the current day's midnight will be retrieved, which can be
52   // slow. If many items are being processed, it is best to get the current
53   // time once at the beginning and pass it for each computation.
54   static base::string16 RelativeDate(const base::Time& time,
55                                      const base::Time* optional_midnight_today);
56
57  private:
58   DISALLOW_IMPLICIT_CONSTRUCTORS(TimeFormat);
59 };
60
61 }  // namespace ui
62
63 #endif  // UI_BASE_L10N_TIME_FORMAT_H_