mirror of
https://review.haiku-os.org/haiku
synced 2025-02-01 03:06:08 +01:00
44f11d0982
* Move relevant parts up into BFormat so other format classes can use those * Adjust BDurationFormat and BTimeUnitFormat for the changes * Remove the "default" date format, it is better to keep only a default locale and let applications create B*Formats from it as needed. * Creating a B*Format without arguments to the constructor now configures it for the default locale, which allows for easy use in standard cases (formatting something with the current language and format) * Creating a B*Format is potentially an expansive operation, it is advised to keep the instance around and reuse it whenever possible. However it must be "refreshed" when the locale changes, for apps which supports that, since it keeps a copy of the language and formatting convention, rather than a pointer to the locale as it did before.
77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
/*
|
|
* Copyright 2010-2014, Haiku, Inc.
|
|
* Distributed under the terms of the MIT Licence.
|
|
*/
|
|
#ifndef _B_DATE_FORMAT_H_
|
|
#define _B_DATE_FORMAT_H_
|
|
|
|
|
|
#include <DateTime.h>
|
|
#include <DateTimeFormat.h>
|
|
#include <FormattingConventions.h>
|
|
#include <Language.h>
|
|
#include <Locker.h>
|
|
|
|
|
|
class BString;
|
|
class BTimeZone;
|
|
|
|
|
|
enum BWeekday {
|
|
B_WEEKDAY_MONDAY = 1,
|
|
B_WEEKDAY_TUESDAY,
|
|
B_WEEKDAY_WEDNESDAY,
|
|
B_WEEKDAY_THURSDAY,
|
|
B_WEEKDAY_FRIDAY,
|
|
B_WEEKDAY_SATURDAY,
|
|
B_WEEKDAY_SUNDAY,
|
|
};
|
|
|
|
|
|
class BDateFormat: public BFormat {
|
|
public:
|
|
BDateFormat(
|
|
const BLanguage* const language = NULL,
|
|
const BFormattingConventions* const
|
|
format = NULL);
|
|
BDateFormat(const BDateFormat &other);
|
|
virtual ~BDateFormat();
|
|
|
|
status_t GetDateFormat(BDateFormatStyle style,
|
|
BString& outFormat) const;
|
|
void SetDateFormat(BDateFormatStyle style,
|
|
const BString& format);
|
|
|
|
// formatting
|
|
|
|
ssize_t Format(char* string, const size_t maxSize,
|
|
const time_t time,
|
|
const BDateFormatStyle style) const;
|
|
status_t Format(BString& string, const time_t time,
|
|
const BDateFormatStyle style,
|
|
const BTimeZone* timeZone = NULL) const;
|
|
status_t Format(BString& string, const BDate& time,
|
|
const BDateFormatStyle style,
|
|
const BTimeZone* timeZone = NULL) const;
|
|
status_t Format(BString& string,
|
|
int*& fieldPositions, int& fieldCount,
|
|
const time_t time,
|
|
const BDateFormatStyle style) const;
|
|
|
|
status_t GetFields(BDateElement*& fields,
|
|
int& fieldCount, BDateFormatStyle style
|
|
) const;
|
|
|
|
status_t GetStartOfWeek(BWeekday* weekday) const;
|
|
|
|
// TODO parsing
|
|
|
|
private:
|
|
icu::DateFormat* _CreateDateFormatter(
|
|
const BString& format) const;
|
|
|
|
};
|
|
|
|
|
|
#endif // _B_DATE_FORMAT_H_
|