1/*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1.  Redistributions of source code must retain the above copyright
8 *     notice, this list of conditions and the following disclaimer.
9 * 2.  Redistributions in binary form must reproduce the above copyright
10 *     notice, this list of conditions and the following disclaimer in the
11 *     documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "PlatformLocale.h"
28#include <wtf/DateMath.h>
29#include <wtf/PassOwnPtr.h>
30
31namespace WebCore {
32
33class LocaleNone : public Locale {
34public:
35    virtual ~LocaleNone();
36
37private:
38    virtual void initializeLocaleData() override final;
39#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
40    virtual String dateFormat() override;
41    virtual String monthFormat() override;
42    virtual String shortMonthFormat() override;
43    virtual String timeFormat() override;
44    virtual String shortTimeFormat() override;
45    virtual String dateTimeFormatWithSeconds() override;
46    virtual String dateTimeFormatWithoutSeconds() override;
47    virtual const Vector<String>& monthLabels() override;
48    virtual const Vector<String>& shortMonthLabels() override;
49    virtual const Vector<String>& standAloneMonthLabels() override;
50    virtual const Vector<String>& shortStandAloneMonthLabels() override;
51    virtual const Vector<String>& timeAMPMLabels() override;
52
53    Vector<String> m_timeAMPMLabels;
54    Vector<String> m_shortMonthLabels;
55    Vector<String> m_monthLabels;
56#endif
57};
58
59PassOwnPtr<Locale> Locale::create(const AtomicString&)
60{
61    return adoptPtr(new LocaleNone());
62}
63
64LocaleNone::~LocaleNone()
65{
66}
67
68void LocaleNone::initializeLocaleData()
69{
70}
71
72#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
73const Vector<String>& LocaleNone::monthLabels()
74{
75    if (!m_monthLabels.isEmpty())
76        return m_monthLabels;
77    m_monthLabels.reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthFullName));
78    for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthFullName); ++i)
79        m_monthLabels.append(WTF::monthFullName[i]);
80    return m_monthLabels;
81}
82
83String LocaleNone::dateFormat()
84{
85    return ASCIILiteral("yyyy-MM-dd");
86}
87
88String LocaleNone::monthFormat()
89{
90    return ASCIILiteral("yyyy-MM");
91}
92
93String LocaleNone::shortMonthFormat()
94{
95    return ASCIILiteral("yyyy-MM");
96}
97
98String LocaleNone::timeFormat()
99{
100    return ASCIILiteral("HH:mm:ss");
101}
102
103String LocaleNone::shortTimeFormat()
104{
105    return ASCIILiteral("HH:mm");
106}
107
108String LocaleNone::dateTimeFormatWithSeconds()
109{
110    return ASCIILiteral("yyyy-MM-dd'T'HH:mm:ss");
111}
112
113String LocaleNone::dateTimeFormatWithoutSeconds()
114{
115    return ASCIILiteral("yyyy-MM-dd'T'HH:mm");
116}
117
118const Vector<String>& LocaleNone::shortMonthLabels()
119{
120    if (!m_shortMonthLabels.isEmpty())
121        return m_shortMonthLabels;
122    m_shortMonthLabels.reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthName));
123    for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthName); ++i)
124        m_shortMonthLabels.append(WTF::monthName[i]);
125    return m_shortMonthLabels;
126}
127
128const Vector<String>& LocaleNone::shortStandAloneMonthLabels()
129{
130    return shortMonthLabels();
131}
132
133const Vector<String>& LocaleNone::standAloneMonthLabels()
134{
135    return monthLabels();
136}
137
138const Vector<String>& LocaleNone::timeAMPMLabels()
139{
140    if (!m_timeAMPMLabels.isEmpty())
141        return m_timeAMPMLabels;
142    m_timeAMPMLabels.reserveCapacity(2);
143    m_timeAMPMLabels.append("AM");
144    m_timeAMPMLabels.append("PM");
145    return m_timeAMPMLabels;
146}
147
148#endif
149
150} // namespace WebCore
151