• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.icu.util;
18 
19 import android.icu.util.Calendar;
20 import android.icu.util.ULocale;
21 
22 import libcore.api.IntraCoreApi;
23 
24 import java.util.Objects;
25 
26 /**
27  * Provide extra functionalities on top of {@link Calendar} public APIs.
28  *
29  * @hide
30  */
31 @IntraCoreApi
32 public class ExtendedCalendar {
33 
34     private final Calendar calendar;
35     private final ULocale uLocale;
36 
ExtendedCalendar(ULocale uLocale)37     private ExtendedCalendar(ULocale uLocale) {
38         this.uLocale = uLocale;
39         this.calendar = Calendar.getInstance(uLocale);
40     }
41 
42     /**
43      * Get an instance
44      *
45      * @param uLocale non-null ULocale
46      * @hide
47      */
48     @IntraCoreApi
getInstance(ULocale uLocale)49     public static ExtendedCalendar getInstance(ULocale uLocale) {
50         Objects.requireNonNull(uLocale);
51         return new ExtendedCalendar(uLocale);
52     }
53 
54     /**
55      * Returns the {@link android.icu.text.DateFormat} pattern for the given date and time styles.
56      * Similiar to {@link Calendar#getDateTimeFormat(int, int, ULocale)} but returns the pattern
57      * string instead of an instance of {@link android.icu.text.DateFormat}.
58      *
59      * @see {@link Calendar#getDateTimeFormat(int, int, ULocale)} for the style parameters.
60      *
61      * @hide
62      */
63     @IntraCoreApi
getDateTimePattern(int dateStyle, int timeStyle)64     public String getDateTimePattern(int dateStyle, int timeStyle) {
65         return Calendar.getDateTimeFormatString(uLocale, calendar.getType(), dateStyle, timeStyle);
66     }
67 }
68