Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / chrome / common / time_format.h
blobdedfc37697ffd171923825dc5b1138371b01c55e
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.
5 #ifndef CHROME_COMMON_TIME_FORMAT_H_
6 #define CHROME_COMMON_TIME_FORMAT_H_
8 #include "base/basictypes.h"
9 #include "base/string16.h"
11 namespace base {
12 class Time;
13 class TimeDelta;
16 // Methods to format time values as strings.
17 class TimeFormat {
18 public:
19 // TimeElapsed, TimeRemaining and TimeRemainingShort functions:
20 // These functions return a localized string of approximate time duration. The
21 // conditions are simpler than PastTime since these functions are used for
22 // in-progress operations and users have different expectations of units.
24 // Returns times in elapsed-format: "3 mins ago", "2 days ago".
25 static string16 TimeElapsed(const base::TimeDelta& delta);
27 // Returns times in remaining-format: "3 mins left", "2 days left".
28 static string16 TimeRemaining(const base::TimeDelta& delta);
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);
35 // Returns times in short-format: "3 mins", "2 days".
36 static string16 TimeRemainingShort(const base::TimeDelta& delta);
38 // For displaying a relative time in the past. This method returns either
39 // "Today", "Yesterday", or an empty string if it's older than that. Returns
40 // the empty string for days in the future.
42 // TODO(brettw): This should be able to handle days in the future like
43 // "Tomorrow".
44 // TODO(tc): This should be able to do things like "Last week". This
45 // requires handling singluar/plural for all languages.
47 // The second parameter is optional, it is midnight of "Now" for relative day
48 // computations: Time::Now().LocalMidnight()
49 // If NULL, the current day's midnight will be retrieved, which can be
50 // slow. If many items are being processed, it is best to get the current
51 // time once at the beginning and pass it for each computation.
52 static string16 RelativeDate(const base::Time& time,
53 const base::Time* optional_midnight_today);
55 private:
56 DISALLOW_IMPLICIT_CONSTRUCTORS(TimeFormat);
59 #endif // CHROME_COMMON_TIME_FORMAT_H_