Implement a formatter for relative dates.

Signed-off-by: Adrien Destugues <[email protected]>

It can give results such as "in 2 hours", "2 days ago", etc.
This is different from BDurationFormat which will just say "1 hour, 2
minute and 36 seconds"
This commit is contained in:
Akshay Agarwal
2017-08-25 21:14:27 +02:00
committed by Adrien Destugues
parent 31e6a56fb3
commit 1e4ab34cd7
3 changed files with 208 additions and 0 deletions
@@ -0,0 +1,44 @@
/*
* Copyright 2017, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Akshay Agarwal <[email protected]>
*/
#ifndef _B_RELATIVE_DATE_TIME_FORMAT_H_
#define _B_RELATIVE_DATE_TIME_FORMAT_H_
#include <Format.h>
#include <SupportDefs.h>
class BString;
#ifndef U_ICU_NAMESPACE
#define U_ICU_NAMESPACE icu
#endif
namespace U_ICU_NAMESPACE {
class GregorianCalendar;
class RelativeDateTimeFormatter;
}
class BRelativeDateTimeFormat: public BFormat {
typedef BFormat Inherited;
public:
BRelativeDateTimeFormat();
BRelativeDateTimeFormat(const BLanguage& language,
const BFormattingConventions& conventions);
BRelativeDateTimeFormat(const BRelativeDateTimeFormat& other);
virtual ~BRelativeDateTimeFormat();
status_t Format(BString& string, const time_t timeValue) const;
private:
U_ICU_NAMESPACE::RelativeDateTimeFormatter* fFormatter;
U_ICU_NAMESPACE::GregorianCalendar* fCalendar;
};
#endif // _B_RELATIVE_DATE_TIME_FORMAT_H_