1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
/*
* Copyright (C) 2014 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: jouyouyun <jouyouwen717@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package calendar
import "strings"
type Day struct {
Year, Month, Day int
}
type festival struct {
name string
startYear int
}
var solarFestivals = map[int][]festival{
101: {
{
name: "元旦",
startYear: 0,
},
},
214: {
{
name: "情人节",
startYear: 0,
},
},
305: {
{
name: "学雷锋纪念日",
startYear: 1963,
},
},
308: {
{
name: "妇女节",
startYear: 0,
},
},
312: {
{
name: "植树节",
startYear: 0,
},
},
401: {
{
name: "愚人节",
startYear: 0,
},
},
415: {
{
name: "全民国家安全教育日",
startYear: 0,
},
},
501: {
{
name: "劳动节",
startYear: 0,
},
},
504: {
{
name: "青年节",
startYear: 0,
},
},
601: {
{
name: "儿童节",
startYear: 0,
},
},
701: {
{
name: "建党节",
startYear: 0,
},
{
name: "香港回归纪念日",
startYear: 1997,
},
},
801: {
{
name: "建军节",
startYear: 0,
},
},
903: {
{
name: "抗日战争胜利纪念日",
startYear: 1945,
},
},
910: {
{
name: "教师节",
startYear: 0,
},
},
1001: {
{
name: "国庆节",
startYear: 0,
},
},
1213: {
{
name: "南京大屠杀死难者国家公祭日",
startYear: 1937,
},
},
1220: {
{
name: "澳门回归纪念",
startYear: 1999,
},
},
1224: {
{
name: "平安夜",
startYear: 0,
},
},
1225: {
{
name: "圣诞节",
startYear: 0,
},
},
1226: {
{
name: "毛泽东诞辰纪念",
startYear: 0,
},
},
}
func (d *Day) Festival() string {
year := d.Year
month := d.Month
day := d.Day
name := ""
var festivals []string
if (month == 5) || (month == 6) {
name = festivalForFatherAndMother(year, month, day)
if name != "" {
festivals = append(festivals, name)
}
}
key := month*100 + day
if solarFestival, ok := solarFestivals[key]; ok {
for _, festival := range solarFestival {
if festival.startYear <= year {
festivals = append(festivals, festival.name)
}
}
}
return strings.Join(festivals, ",")
}
func festivalForFatherAndMother(year, month, day int) string {
var disparityMotherDay, disparityFatherDay, fatherDay, i, motherDay int
var leapYear int
for i = 1900; i <= year; i++ {
if (i%400 == 0) || ((i%100 != 0) && (i%4 == 0)) {
leapYear = leapYear + 1
}
}
if month == 5 {
disparityMotherDay = (((year-1899)*365 + leapYear) - (31 + 30 + 31 + 31 + 30 + 31 + 30 + 31)) % 7
motherDay = 14 - disparityMotherDay
if day == motherDay {
return "母亲节"
} else {
return ""
}
}
if month == 6 {
disparityFatherDay = (((year-1899)*365 + leapYear) - (30 + 31 + 31 + 30 + 31 + 30 + 31)) % 7
fatherDay = 21 - disparityFatherDay
if day == fatherDay {
return "父亲节"
} else {
return ""
}
}
return ""
}
|