Repository navigation
Expand file tree
/
Copy pathtcutil.py
More file actions
145 lines (124 loc) · 5.08 KB
/
Copy pathtcutil.py
File metadata and controls
145 lines (124 loc) · 5.08 KB
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
#rpb time&calenderUtil
import ConfigManager
import getCalendar
import datetime
class TimeManager:
def __init__(self):
"""時間を管理する"""
self.config = ConfigManager.ConfigManager()
def replace_milliseconds(self, minutes):
"""
引数の分数をミリ秒に変換して返す関数
Args:
minutes (int): 変換したい分数
Returns:
int: 分数をミリ秒に変換した値
"""
milliseconds = minutes * 60 * 1000
return int(milliseconds)
def calculate_time_difference(self, current_time, program_start_time):
"""
現在時刻と番組開始時間の差をミリ秒で返す関数
Args:
current_time (datetime.datetime): 現在の日時
program_start_time (datetime.datetime): 番組の開始時間
Returns:
int: 現在時刻と番組開始時間の差をミリ秒で表した値
"""
time_difference = program_start_time - current_time
return int(time_difference.total_seconds() * 1000)
class CalendarUtil:
def __init__(self):
"""カレンダーを扱う"""
self.dateData = getCalendar.Calendar()
def getDateValue(self):
"""日付データを取得(ラジオの日付ルール: 翌朝5時までを今日として扱う)"""
current = datetime.datetime.now()
# ラジオの日付ルール: 翌朝5時までを今日として扱う
# 現在時刻が5時未満の場合は、前日の日付を使用
if current.hour < 5:
# 5時未満の場合は前日の日付を基準とする
base_date = current.date() - datetime.timedelta(days=1)
else:
# 5時以降の場合は当日の日付を基準とする
base_date = current.date()
year = base_date.year
calendar = self.dateData.generate_calendar(year)
start_date = base_date
week_data = self.dateData.get_week_dates(start_date)
results = []
for date in week_data:
year, month, day = date
# 月末・年末処理
if day > 31:
month += 1
year, month = self.dateData.adjust_date(year, month)
formatted_data = f"{year}/{month}/{day}"
results.append(formatted_data)
return results
def transform_date(self, date):
"""日付データをYYYYMMDD形式に変換して返す"""
if "/" in date:
# "2026/1/1" -> "20260101"
parts = date.split("/")
if len(parts) >= 3:
year = parts[0]
month = parts[1].zfill(2)
day = parts[2].zfill(2)
return f"{year}{month}{day}"
else:
# フォールバック: カンマ区切り形式に変換(後方互換性のため)
return date.replace("/", ",")
if "-" in date:
# "2026-1-1" -> "20260101"
parts = date.split("-")
if len(parts) >= 3:
year = parts[0]
month = parts[1].zfill(2)
day = parts[2].zfill(2)
return f"{year}{month}{day}"
else:
return date.replace("-", "")
if "," in date:
# "2026,1,1" -> "20260101"
parts = date.split(",")
if len(parts) >= 3:
year = parts[0].strip()
month = parts[1].strip().zfill(2)
day = parts[2].strip().zfill(2)
return f"{year}{month}{day}"
# 既にYYYYMMDD形式の場合
if len(date) == 8 and date.isdigit():
return date
# その他の形式はそのまま返す(後方互換性のため)
return date
def get_radio_date(self):
"""ラジオの日付ルールに従った日付を取得(翌朝5時までを今日として扱う)"""
current = datetime.datetime.now()
# ラジオの日付ルール: 翌朝5時までを今日として扱う
# 現在時刻が5時未満の場合は、前日の日付を使用
if current.hour < 5:
# 5時未満の場合は前日の日付を基準とする
base_date = current.date() - datetime.timedelta(days=1)
else:
# 5時以降の場合は当日の日付を基準とする
base_date = current.date()
return base_date.strftime('%Y%m%d')
def get_radio_base_datetime(self):
"""ラジオ基準日の0:00:00 datetimeを返す"""
radio_date = self.get_radio_date()
return datetime.datetime(
int(radio_date[:4]),
int(radio_date[4:6]),
int(radio_date[6:8]),
)
def format_now(self):
now = datetime.datetime.now()
# 年・月・日・時・分・秒を取得
year = now.year
month = now.month
day = now.day
hour = now.hour
minute = now.minute
# 結果を出力
return int(f"{year}{month}{day}{hour}{minute}")