Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
* vim: set ts=8 sts=2 et sw=2 tw=80:
3
* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef builtin_intl_RelativeTimeFormat_h
8
#define builtin_intl_RelativeTimeFormat_h
9
10
#include "mozilla/Attributes.h"
11
12
#include <stdint.h>
13
14
#include "builtin/SelfHostingDefines.h"
15
#include "js/Class.h"
16
#include "vm/NativeObject.h"
17
18
struct URelativeDateTimeFormatter;
19
20
namespace js {
21
22
class RelativeTimeFormatObject : public NativeObject {
23
public:
24
static const JSClass class_;
25
static const JSClass& protoClass_;
26
27
static constexpr uint32_t INTERNALS_SLOT = 0;
28
static constexpr uint32_t URELATIVE_TIME_FORMAT_SLOT = 1;
29
static constexpr uint32_t SLOT_COUNT = 2;
30
31
static_assert(INTERNALS_SLOT == INTL_INTERNALS_OBJECT_SLOT,
32
"INTERNALS_SLOT must match self-hosting define for internals "
33
"object slot");
34
35
// Estimated memory use for URelativeDateTimeFormatter.
36
static constexpr size_t EstimatedMemoryUse = 278;
37
38
URelativeDateTimeFormatter* getRelativeDateTimeFormatter() const {
39
const auto& slot = getFixedSlot(URELATIVE_TIME_FORMAT_SLOT);
40
if (slot.isUndefined()) {
41
return nullptr;
42
}
43
return static_cast<URelativeDateTimeFormatter*>(slot.toPrivate());
44
}
45
46
void setRelativeDateTimeFormatter(URelativeDateTimeFormatter* rtf) {
47
setFixedSlot(URELATIVE_TIME_FORMAT_SLOT, PrivateValue(rtf));
48
}
49
50
private:
51
static const JSClassOps classOps_;
52
static const ClassSpec classSpec_;
53
54
static void finalize(JSFreeOp* fop, JSObject* obj);
55
};
56
57
/**
58
* Returns a relative time as a string formatted according to the effective
59
* locale and the formatting options of the given RelativeTimeFormat.
60
*
61
* |t| should be a number representing a number to be formatted.
62
* |unit| should be "second", "minute", "hour", "day", "week", "month",
63
* "quarter", or "year".
64
* |numeric| should be "always" or "auto".
65
*
66
* Usage: formatted = intl_FormatRelativeTime(relativeTimeFormat, t,
67
* unit, numeric, formatToParts)
68
*/
69
extern MOZ_MUST_USE bool intl_FormatRelativeTime(JSContext* cx, unsigned argc,
70
JS::Value* vp);
71
72
} // namespace js
73
74
#endif /* builtin_intl_RelativeTimeFormat_h */