Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2010 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 CHROME_COMMON_TIME_FORMAT_H__
      6 #define CHROME_COMMON_TIME_FORMAT_H__
      7 #pragma once
      8 
      9 // This file defines methods to format time values as strings.
     10 
     11 #include "base/string16.h"
     12 
     13 #include "unicode/smpdtfmt.h"
     14 
     15 namespace base {
     16 class Time;
     17 class TimeDelta;
     18 }
     19 
     20 class TimeFormat {
     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 short-format: "3 mins", "2 days".
     34   static string16 TimeRemainingShort(const base::TimeDelta& delta);
     35 
     36   // For displaying a relative time in the past.  This method returns either
     37   // "Today", "Yesterday", or an empty string if it's older than that.
     38   //
     39   // TODO(brettw): This should be able to handle days in the future like
     40   //    "Tomorrow".
     41   // TODO(tc): This should be able to do things like "Last week".  This
     42   //    requires handling singluar/plural for all languages.
     43   //
     44   // The second parameter is optional, it is midnight of "Now" for relative day
     45   // computations: Time::Now().LocalMidnight()
     46   // If NULL, the current day's midnight will be retrieved, which can be
     47   // slow. If many items are being processed, it is best to get the current
     48   // time once at the beginning and pass it for each computation.
     49   static string16 RelativeDate(const base::Time& time,
     50                                const base::Time* optional_midnight_today);
     51 };
     52 
     53 #endif  // CHROME_COMMON_TIME_FORMAT_H__
     54