2016-11-22 02:58:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_DateTimeFormat_h
|
|
|
|
#define mozilla_DateTimeFormat_h
|
|
|
|
|
|
|
|
#include <time.h>
|
2017-02-09 01:08:30 +03:00
|
|
|
#include "gtest/MozGtestFriend.h"
|
2018-12-18 14:42:04 +03:00
|
|
|
#include "nsDataHashtable.h"
|
2017-12-07 03:52:51 +03:00
|
|
|
#include "nsString.h"
|
2016-11-22 02:58:37 +03:00
|
|
|
#include "prtime.h"
|
2017-02-07 01:02:38 +03:00
|
|
|
#include "unicode/udat.h"
|
2016-11-22 02:58:37 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2017-08-03 10:46:55 +03:00
|
|
|
enum nsDateFormatSelector : long {
|
|
|
|
// Do not change the order of the values below (see bug 1225696).
|
|
|
|
kDateFormatNone = 0, // do not include the date in the format string
|
|
|
|
kDateFormatLong, // provides the long date format for the given locale
|
|
|
|
kDateFormatShort, // provides the short date format for the given locale
|
|
|
|
kDateFormatYearMonth, // formats using only the year and month
|
|
|
|
kDateFormatWeekday, // week day (e.g. Mon, Tue)
|
|
|
|
kDateFormatYearMonthLong, // long version of kDateFormatYearMonth
|
|
|
|
kDateFormatMonthLong // long format of month name only
|
|
|
|
};
|
|
|
|
|
|
|
|
enum nsTimeFormatSelector : long {
|
|
|
|
kTimeFormatNone = 0, // don't include the time in the format string
|
2018-09-07 17:47:51 +03:00
|
|
|
kTimeFormatSeconds, // provides the time format with seconds in the given
|
|
|
|
// locale
|
|
|
|
kTimeFormatNoSeconds // provides the time format without seconds in the given
|
|
|
|
// locale
|
2017-08-03 10:46:55 +03:00
|
|
|
};
|
|
|
|
|
2016-11-22 02:58:37 +03:00
|
|
|
class DateTimeFormat {
|
|
|
|
public:
|
|
|
|
// performs a locale sensitive date formatting operation on the PRTime
|
|
|
|
// parameter
|
|
|
|
static nsresult FormatPRTime(const nsDateFormatSelector aDateFormatSelector,
|
|
|
|
const nsTimeFormatSelector aTimeFormatSelector,
|
|
|
|
const PRTime aPrTime, nsAString& aStringOut);
|
|
|
|
|
|
|
|
// performs a locale sensitive date formatting operation on the PRExplodedTime
|
|
|
|
// parameter
|
|
|
|
static nsresult FormatPRExplodedTime(
|
|
|
|
const nsDateFormatSelector aDateFormatSelector,
|
|
|
|
const nsTimeFormatSelector aTimeFormatSelector,
|
|
|
|
const PRExplodedTime* aExplodedTime, nsAString& aStringOut);
|
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
private:
|
|
|
|
DateTimeFormat() = delete;
|
|
|
|
|
|
|
|
static nsresult Initialize();
|
2018-12-18 14:42:04 +03:00
|
|
|
static void DeleteCache();
|
|
|
|
static const size_t kMaxCachedFormats = 15;
|
2016-11-22 02:58:37 +03:00
|
|
|
|
2017-02-07 01:02:38 +03:00
|
|
|
FRIEND_TEST(DateTimeFormat, FormatPRExplodedTime);
|
2017-02-09 01:08:30 +03:00
|
|
|
FRIEND_TEST(DateTimeFormat, DateFormatSelectors);
|
2017-04-11 18:07:00 +03:00
|
|
|
FRIEND_TEST(DateTimeFormat, FormatPRExplodedTimeForeign);
|
|
|
|
FRIEND_TEST(DateTimeFormat, DateFormatSelectorsForeign);
|
2017-02-07 01:02:38 +03:00
|
|
|
|
|
|
|
// performs a locale sensitive date formatting operation on the UDate
|
|
|
|
// parameter
|
|
|
|
static nsresult FormatUDateTime(
|
|
|
|
const nsDateFormatSelector aDateFormatSelector,
|
|
|
|
const nsTimeFormatSelector aTimeFormatSelector, const UDate aUDateTime,
|
|
|
|
const PRTimeParameters* aTimeParameters, nsAString& aStringOut);
|
|
|
|
|
2016-11-22 02:58:37 +03:00
|
|
|
static nsCString* mLocale;
|
2018-12-18 14:42:04 +03:00
|
|
|
static nsDataHashtable<nsCStringHashKey, UDateFormat*>* mFormatCache;
|
2016-11-22 02:58:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_DateTimeFormat_h */
|