回答編集履歴
5
補足追記
answer
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
もはや作ってしまった方が早いです。
|
2
|
+
|
2
3
|
jpholidayはメンテはされているようですが、一般的に使うライブラリである、という感じはうけません。また特別休日の追加はできるようなのですが、ベースとなる休日を削除はできなさそうなので、質問者の会社が「来週の月曜振替休日は年間の調整で出勤日にします!」みたいな状況には対応できないかもです。
|
3
4
|
|
5
|
+
また、最初は面倒ですが、このように作っておくことで、以下メリットがあると思います。
|
6
|
+
- 来年の予定の登録や、今年の日程の修正が必要になった際に、登録がやりやすい(会社の休日一覧表とか、自分の年休日とかをそのまま登録すればよく、何か変更して別の日を登録するといった、登録に頭を悩ませることは不要)
|
7
|
+
- 今後「週報の暫定版を、休日では無い週末に提出せよ!」みたいな別の要件が発生した場合に拡張がしやすい
|
8
|
+
|
9
|
+
データを、外側でファイル定義するとかは、もはや応用なので、ご自分でカスタマイズしてみてください。terateilはプログラマーの問題解決の場ですので、「完成されて後はコード見なくてもOK!といった回答」ではなく、「質問者様のコードに組み込んでどんどん拡張していただける元となる回答」を心がけました。
|
10
|
+
|
4
11
|
```Python
|
5
12
|
class MyDateTime:
|
6
13
|
# Prioritize upper set of days, ignore lower duplicated elements.
|
4
一部修正
answer
CHANGED
@@ -3,11 +3,14 @@
|
|
3
3
|
|
4
4
|
```Python
|
5
5
|
class MyDateTime:
|
6
|
+
# Prioritize upper set of days, ignore lower duplicated elements.
|
7
|
+
# Of courese, you must register the future calendars,
|
8
|
+
# in odrder not to work on many days! :-)
|
9
|
+
special_workdays = {}
|
6
10
|
special_holidays = {
|
7
11
|
'2020-1-2', '2020-1-3', '2020-8-11', '2020-8-12', '2020-8-13', '2020-8-14',
|
8
12
|
'2020-12-29', '2020-12-30', '2020-12-31'
|
9
13
|
}
|
10
|
-
special_workdays = {}
|
11
14
|
national_holidays = {
|
12
15
|
'2020-1-1', '2020-1-13', '2020-2-11', '2020-2-23', '2020-2-24',
|
13
16
|
'2020-3-20', '2020-4-29', '2020-5-3', '2020-5-4', '2020-5-5', '2020-5-6',
|
@@ -22,10 +25,10 @@
|
|
22
25
|
|
23
26
|
@classmethod
|
24
27
|
def is_workday(cls, day):
|
28
|
+
if day in map(cls.strptime, cls.special_workdays):
|
29
|
+
return True
|
25
30
|
if day in map(cls.strptime, cls.special_holidays):
|
26
31
|
return False
|
27
|
-
if day in map(cls.strptime, cls.special_workdays):
|
28
|
-
return True
|
29
32
|
if day in map(cls.strptime, cls.national_holidays):
|
30
33
|
return False
|
31
34
|
return not (day.weekday() == 5 or day.weekday() == 6)
|
3
誤字の修正
answer
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
'2020-1-2', '2020-1-3', '2020-8-11', '2020-8-12', '2020-8-13', '2020-8-14',
|
8
8
|
'2020-12-29', '2020-12-30', '2020-12-31'
|
9
9
|
}
|
10
|
-
special_workdays = {
|
10
|
+
special_workdays = {}
|
11
11
|
national_holidays = {
|
12
12
|
'2020-1-1', '2020-1-13', '2020-2-11', '2020-2-23', '2020-2-24',
|
13
13
|
'2020-3-20', '2020-4-29', '2020-5-3', '2020-5-4', '2020-5-5', '2020-5-6',
|
2
判断ロジックの修正
answer
CHANGED
@@ -2,20 +2,18 @@
|
|
2
2
|
jpholidayはメンテはされているようですが、一般的に使うライブラリである、という感じはうけません。また特別休日の追加はできるようなのですが、ベースとなる休日を削除はできなさそうなので、質問者の会社が「来週の月曜振替休日は年間の調整で出勤日にします!」みたいな状況には対応できないかもです。
|
3
3
|
|
4
4
|
```Python
|
5
|
-
import datetime
|
6
|
-
|
7
5
|
class MyDateTime:
|
6
|
+
special_holidays = {
|
7
|
+
'2020-1-2', '2020-1-3', '2020-8-11', '2020-8-12', '2020-8-13', '2020-8-14',
|
8
|
+
'2020-12-29', '2020-12-30', '2020-12-31'
|
9
|
+
}
|
10
|
+
special_workdays = {'2020-11-23'}
|
8
11
|
national_holidays = {
|
9
12
|
'2020-1-1', '2020-1-13', '2020-2-11', '2020-2-23', '2020-2-24',
|
10
13
|
'2020-3-20', '2020-4-29', '2020-5-3', '2020-5-4', '2020-5-5', '2020-5-6',
|
11
14
|
'2020-7-23', '2020-7-24', '2020-8-10', '2020-9-21', '2020-9-22',
|
12
15
|
'2020-11-3', '2020-11-23'
|
13
16
|
}
|
14
|
-
special_holidays = {
|
15
|
-
'2020-1-2', '2020-1-3', '2020-8-11', '2020-8-12', '2020-8-13', '2020-8-14',
|
16
|
-
'2020-12-29', '2020-12-30', '2020-12-31'
|
17
|
-
}
|
18
|
-
special_workdays = {}
|
19
17
|
|
20
18
|
@classmethod
|
21
19
|
def strptime(cls, s):
|
@@ -24,12 +22,12 @@
|
|
24
22
|
|
25
23
|
@classmethod
|
26
24
|
def is_workday(cls, day):
|
27
|
-
if day in map(cls.strptime, cls.national_holidays):
|
28
|
-
return False
|
29
25
|
if day in map(cls.strptime, cls.special_holidays):
|
30
26
|
return False
|
31
27
|
if day in map(cls.strptime, cls.special_workdays):
|
32
28
|
return True
|
29
|
+
if day in map(cls.strptime, cls.national_holidays):
|
30
|
+
return False
|
33
31
|
return not (day.weekday() == 5 or day.weekday() == 6)
|
34
32
|
|
35
33
|
@classmethod
|
1
微修正
answer
CHANGED
@@ -30,9 +30,7 @@
|
|
30
30
|
return False
|
31
31
|
if day in map(cls.strptime, cls.special_workdays):
|
32
32
|
return True
|
33
|
-
|
33
|
+
return not (day.weekday() == 5 or day.weekday() == 6)
|
34
|
-
return False
|
35
|
-
return True
|
36
34
|
|
37
35
|
@classmethod
|
38
36
|
def is_holiday(cls, day):
|