11cb0ef41Sopenharmony_ci// © 2016 and later: Unicode, Inc. and others.
21cb0ef41Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html
31cb0ef41Sopenharmony_ci/*
41cb0ef41Sopenharmony_ci*******************************************************************************
51cb0ef41Sopenharmony_ci* Copyright (C) 2007-2012, International Business Machines Corporation and
61cb0ef41Sopenharmony_ci* others. All Rights Reserved.
71cb0ef41Sopenharmony_ci*******************************************************************************
81cb0ef41Sopenharmony_ci*/
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "utypeinfo.h"  // for 'typeid' to work
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci#include "unicode/utypes.h"
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci#if !UCONFIG_NO_FORMATTING
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci#include "unicode/dtrule.h"
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciU_NAMESPACE_BEGIN
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciUOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateTimeRule)
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciDateTimeRule::DateTimeRule(int32_t month,
231cb0ef41Sopenharmony_ci                           int32_t dayOfMonth,
241cb0ef41Sopenharmony_ci                           int32_t millisInDay,
251cb0ef41Sopenharmony_ci                           TimeRuleType timeType)
261cb0ef41Sopenharmony_ci: fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(0), fWeekInMonth(0), fMillisInDay(millisInDay),
271cb0ef41Sopenharmony_ci  fDateRuleType(DateTimeRule::DOM), fTimeRuleType(timeType) {
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ciDateTimeRule::DateTimeRule(int32_t month,
311cb0ef41Sopenharmony_ci                           int32_t weekInMonth,
321cb0ef41Sopenharmony_ci                           int32_t dayOfWeek,
331cb0ef41Sopenharmony_ci                           int32_t millisInDay,
341cb0ef41Sopenharmony_ci                           TimeRuleType timeType)
351cb0ef41Sopenharmony_ci: fMonth(month), fDayOfMonth(0), fDayOfWeek(dayOfWeek), fWeekInMonth(weekInMonth), fMillisInDay(millisInDay),
361cb0ef41Sopenharmony_ci  fDateRuleType(DateTimeRule::DOW), fTimeRuleType(timeType) {
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciDateTimeRule::DateTimeRule(int32_t month,
401cb0ef41Sopenharmony_ci                           int32_t dayOfMonth,
411cb0ef41Sopenharmony_ci                           int32_t dayOfWeek,
421cb0ef41Sopenharmony_ci                           UBool after,
431cb0ef41Sopenharmony_ci                           int32_t millisInDay,
441cb0ef41Sopenharmony_ci                           TimeRuleType timeType)
451cb0ef41Sopenharmony_ci: UObject(),
461cb0ef41Sopenharmony_ci  fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(dayOfWeek), fWeekInMonth(0), fMillisInDay(millisInDay),
471cb0ef41Sopenharmony_ci  fTimeRuleType(timeType) {
481cb0ef41Sopenharmony_ci    if (after) {
491cb0ef41Sopenharmony_ci        fDateRuleType = DateTimeRule::DOW_GEQ_DOM;
501cb0ef41Sopenharmony_ci    } else {
511cb0ef41Sopenharmony_ci        fDateRuleType = DateTimeRule::DOW_LEQ_DOM;
521cb0ef41Sopenharmony_ci    }
531cb0ef41Sopenharmony_ci}
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ciDateTimeRule::DateTimeRule(const DateTimeRule& source)
561cb0ef41Sopenharmony_ci: UObject(source),
571cb0ef41Sopenharmony_ci  fMonth(source.fMonth), fDayOfMonth(source.fDayOfMonth), fDayOfWeek(source.fDayOfWeek),
581cb0ef41Sopenharmony_ci  fWeekInMonth(source.fWeekInMonth), fMillisInDay(source.fMillisInDay),
591cb0ef41Sopenharmony_ci  fDateRuleType(source.fDateRuleType), fTimeRuleType(source.fTimeRuleType) {
601cb0ef41Sopenharmony_ci}
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ciDateTimeRule::~DateTimeRule() {
631cb0ef41Sopenharmony_ci}
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ciDateTimeRule*
661cb0ef41Sopenharmony_ciDateTimeRule::clone() const {
671cb0ef41Sopenharmony_ci    return new DateTimeRule(*this);
681cb0ef41Sopenharmony_ci}
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ciDateTimeRule&
711cb0ef41Sopenharmony_ciDateTimeRule::operator=(const DateTimeRule& right) {
721cb0ef41Sopenharmony_ci    if (this != &right) {
731cb0ef41Sopenharmony_ci        fMonth = right.fMonth;
741cb0ef41Sopenharmony_ci        fDayOfMonth = right.fDayOfMonth;
751cb0ef41Sopenharmony_ci        fDayOfWeek = right.fDayOfWeek;
761cb0ef41Sopenharmony_ci        fWeekInMonth = right.fWeekInMonth;
771cb0ef41Sopenharmony_ci        fMillisInDay = right.fMillisInDay;
781cb0ef41Sopenharmony_ci        fDateRuleType = right.fDateRuleType;
791cb0ef41Sopenharmony_ci        fTimeRuleType = right.fTimeRuleType;
801cb0ef41Sopenharmony_ci    }
811cb0ef41Sopenharmony_ci    return *this;
821cb0ef41Sopenharmony_ci}
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_cibool
851cb0ef41Sopenharmony_ciDateTimeRule::operator==(const DateTimeRule& that) const {
861cb0ef41Sopenharmony_ci    return ((this == &that) ||
871cb0ef41Sopenharmony_ci            (typeid(*this) == typeid(that) &&
881cb0ef41Sopenharmony_ci            fMonth == that.fMonth &&
891cb0ef41Sopenharmony_ci            fDayOfMonth == that.fDayOfMonth &&
901cb0ef41Sopenharmony_ci            fDayOfWeek == that.fDayOfWeek &&
911cb0ef41Sopenharmony_ci            fWeekInMonth == that.fWeekInMonth &&
921cb0ef41Sopenharmony_ci            fMillisInDay == that.fMillisInDay &&
931cb0ef41Sopenharmony_ci            fDateRuleType == that.fDateRuleType &&
941cb0ef41Sopenharmony_ci            fTimeRuleType == that.fTimeRuleType));
951cb0ef41Sopenharmony_ci}
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_cibool
981cb0ef41Sopenharmony_ciDateTimeRule::operator!=(const DateTimeRule& that) const {
991cb0ef41Sopenharmony_ci    return !operator==(that);
1001cb0ef41Sopenharmony_ci}
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_ciDateTimeRule::DateRuleType
1031cb0ef41Sopenharmony_ciDateTimeRule::getDateRuleType() const {
1041cb0ef41Sopenharmony_ci    return fDateRuleType;
1051cb0ef41Sopenharmony_ci}
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ciDateTimeRule::TimeRuleType
1081cb0ef41Sopenharmony_ciDateTimeRule::getTimeRuleType() const {
1091cb0ef41Sopenharmony_ci    return fTimeRuleType;
1101cb0ef41Sopenharmony_ci}
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ciint32_t
1131cb0ef41Sopenharmony_ciDateTimeRule::getRuleMonth() const {
1141cb0ef41Sopenharmony_ci    return fMonth;
1151cb0ef41Sopenharmony_ci}
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ciint32_t
1181cb0ef41Sopenharmony_ciDateTimeRule::getRuleDayOfMonth() const {
1191cb0ef41Sopenharmony_ci    return fDayOfMonth;
1201cb0ef41Sopenharmony_ci}
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ciint32_t
1231cb0ef41Sopenharmony_ciDateTimeRule::getRuleDayOfWeek() const {
1241cb0ef41Sopenharmony_ci    return fDayOfWeek;
1251cb0ef41Sopenharmony_ci}
1261cb0ef41Sopenharmony_ci
1271cb0ef41Sopenharmony_ciint32_t
1281cb0ef41Sopenharmony_ciDateTimeRule::getRuleWeekInMonth() const {
1291cb0ef41Sopenharmony_ci    return fWeekInMonth;
1301cb0ef41Sopenharmony_ci}
1311cb0ef41Sopenharmony_ci
1321cb0ef41Sopenharmony_ciint32_t
1331cb0ef41Sopenharmony_ciDateTimeRule::getRuleMillisInDay() const {
1341cb0ef41Sopenharmony_ci    return fMillisInDay;
1351cb0ef41Sopenharmony_ci}
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ciU_NAMESPACE_END
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci#endif /* #if !UCONFIG_NO_FORMATTING */
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci//eof
142