tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

dtrule.cpp (3959B)


      1 // © 2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html
      3 /*
      4 *******************************************************************************
      5 * Copyright (C) 2007-2012, International Business Machines Corporation and
      6 * others. All Rights Reserved.
      7 *******************************************************************************
      8 */
      9 
     10 #include "utypeinfo.h"  // for 'typeid' to work
     11 
     12 #include "unicode/utypes.h"
     13 
     14 #if !UCONFIG_NO_FORMATTING
     15 
     16 #include "unicode/dtrule.h"
     17 
     18 U_NAMESPACE_BEGIN
     19 
     20 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateTimeRule)
     21 
     22 DateTimeRule::DateTimeRule(int32_t month,
     23                           int32_t dayOfMonth,
     24                           int32_t millisInDay,
     25                           TimeRuleType timeType)
     26 : fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(0), fWeekInMonth(0), fMillisInDay(millisInDay),
     27  fDateRuleType(DateTimeRule::DOM), fTimeRuleType(timeType) {
     28 }
     29 
     30 DateTimeRule::DateTimeRule(int32_t month,
     31                           int32_t weekInMonth,
     32                           int32_t dayOfWeek,
     33                           int32_t millisInDay,
     34                           TimeRuleType timeType)
     35 : fMonth(month), fDayOfMonth(0), fDayOfWeek(dayOfWeek), fWeekInMonth(weekInMonth), fMillisInDay(millisInDay),
     36  fDateRuleType(DateTimeRule::DOW), fTimeRuleType(timeType) {
     37 }
     38 
     39 DateTimeRule::DateTimeRule(int32_t month,
     40                           int32_t dayOfMonth,
     41                           int32_t dayOfWeek,
     42                           UBool after,
     43                           int32_t millisInDay,
     44                           TimeRuleType timeType)
     45 : UObject(),
     46  fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(dayOfWeek), fWeekInMonth(0), fMillisInDay(millisInDay),
     47  fTimeRuleType(timeType) {
     48    if (after) {
     49        fDateRuleType = DateTimeRule::DOW_GEQ_DOM;
     50    } else {
     51        fDateRuleType = DateTimeRule::DOW_LEQ_DOM;
     52    }
     53 }
     54 
     55 DateTimeRule::DateTimeRule(const DateTimeRule& source)
     56 : UObject(source),
     57  fMonth(source.fMonth), fDayOfMonth(source.fDayOfMonth), fDayOfWeek(source.fDayOfWeek),
     58  fWeekInMonth(source.fWeekInMonth), fMillisInDay(source.fMillisInDay),
     59  fDateRuleType(source.fDateRuleType), fTimeRuleType(source.fTimeRuleType) {
     60 }
     61 
     62 DateTimeRule::~DateTimeRule() {
     63 }
     64 
     65 DateTimeRule*
     66 DateTimeRule::clone() const {
     67    return new DateTimeRule(*this);
     68 }
     69 
     70 DateTimeRule&
     71 DateTimeRule::operator=(const DateTimeRule& right) {
     72    if (this != &right) {
     73        fMonth = right.fMonth;
     74        fDayOfMonth = right.fDayOfMonth;
     75        fDayOfWeek = right.fDayOfWeek;
     76        fWeekInMonth = right.fWeekInMonth;
     77        fMillisInDay = right.fMillisInDay;
     78        fDateRuleType = right.fDateRuleType;
     79        fTimeRuleType = right.fTimeRuleType;
     80    }
     81    return *this;
     82 }
     83 
     84 bool
     85 DateTimeRule::operator==(const DateTimeRule& that) const {
     86    return ((this == &that) ||
     87            (typeid(*this) == typeid(that) &&
     88            fMonth == that.fMonth &&
     89            fDayOfMonth == that.fDayOfMonth &&
     90            fDayOfWeek == that.fDayOfWeek &&
     91            fWeekInMonth == that.fWeekInMonth &&
     92            fMillisInDay == that.fMillisInDay &&
     93            fDateRuleType == that.fDateRuleType &&
     94            fTimeRuleType == that.fTimeRuleType));
     95 }
     96 
     97 bool
     98 DateTimeRule::operator!=(const DateTimeRule& that) const {
     99    return !operator==(that);
    100 }
    101 
    102 DateTimeRule::DateRuleType
    103 DateTimeRule::getDateRuleType() const {
    104    return fDateRuleType;
    105 }
    106 
    107 DateTimeRule::TimeRuleType
    108 DateTimeRule::getTimeRuleType() const {
    109    return fTimeRuleType;
    110 }
    111 
    112 int32_t
    113 DateTimeRule::getRuleMonth() const {
    114    return fMonth;
    115 }
    116 
    117 int32_t
    118 DateTimeRule::getRuleDayOfMonth() const {
    119    return fDayOfMonth;
    120 }
    121 
    122 int32_t
    123 DateTimeRule::getRuleDayOfWeek() const {
    124    return fDayOfWeek;
    125 }
    126 
    127 int32_t
    128 DateTimeRule::getRuleWeekInMonth() const {
    129    return fWeekInMonth;
    130 }
    131 
    132 int32_t
    133 DateTimeRule::getRuleMillisInDay() const {
    134    return fMillisInDay;
    135 }
    136 
    137 U_NAMESPACE_END
    138 
    139 #endif /* #if !UCONFIG_NO_FORMATTING */
    140 
    141 //eof