1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html#License
3/*
4 *******************************************************************************
5 * Copyright (C) 2007, International Business Machines Corporation and         *
6 * others. All Rights Reserved.                                                *
7 *******************************************************************************
8 */
9package com.ibm.icu.dev.test.util;
10
11import com.ibm.icu.text.DateFormat;
12
13/**
14 * @author srl
15 *
16 */
17public class DateTimeStyleSet extends FieldsSet {
18
19    private static final int DTS_DATE = 0;
20    private static final String kDATE = "DATE";
21    private static final int DTS_TIME = 1;
22    private static final String kTIME = "TIME";
23    private static final int DTS_COUNT = 2;
24
25    private static final String kRELATIVE_ = "RELATIVE_";
26
27    private int getOrNone(int which) {
28        if(!isSet(which)) {
29            return DateFormat.NONE;
30        } else {
31            return get(which);
32        }
33    }
34
35    public DateTimeStyleSet() {
36        super(FieldsSet.NO_ENUM, DTS_COUNT);
37    }
38
39    public int getDateStyle() {
40        return getOrNone(DTS_DATE);
41    }
42
43    public int getTimeStyle() {
44        return getOrNone(DTS_TIME);
45    }
46
47    protected void handleParseValue(FieldsSet inheritFrom, int field, String substr) {
48        if(substr.startsWith(kRELATIVE_)) {
49            parseValueEnum(DebugUtilitiesData.UDateFormatStyle, inheritFrom, field, substr.substring(kRELATIVE_.length()));
50            if(isSet(field)) {
51                set(field, get(field) | DateFormat.RELATIVE);
52            }
53        } else {
54            parseValueEnum(DebugUtilitiesData.UDateFormatStyle, inheritFrom, field, substr);
55        }
56    }
57
58    protected int handleParseName(FieldsSet inheritFrom, String name, String substr) {
59        if(name.equals(kDATE)) {
60            return DTS_DATE;
61        } else if(name.equals(kTIME)) {
62            return DTS_TIME;
63        } else {
64            throw new IllegalArgumentException("Bad field: " + name);
65        }
66    }
67}
68