Skip to content

Commit 2f47aa3

Browse files
committed
Merge branch 'develop'
# Conflicts: # .github/workflows/build.yml
2 parents 39d403b + f29e0ed commit 2f47aa3

File tree

8 files changed

+173
-13
lines changed

8 files changed

+173
-13
lines changed

.github/workflows/build.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build
2+
3+
on:
4+
schedule:
5+
- cron: '0 15 31 12 *'
6+
workflow_dispatch:
7+
push:
8+
branches: [ build-test ]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Cache Composer packages
18+
id: composer-cache
19+
uses: actions/cache@v4
20+
with:
21+
path: vendor
22+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
23+
restore-keys: |
24+
${{ runner.os }}-php-
25+
26+
- name: Install dependencies
27+
run: composer install --prefer-dist --no-progress
28+
29+
- name: build api files
30+
env:
31+
TZ: 'Asia/Tokyo'
32+
run: composer build
33+
34+
- name: commit and push
35+
run: |
36+
git add -N .
37+
if ! git diff --exit-code --quiet
38+
then
39+
git config user.email "matsuoshi@gmail.com"
40+
git config user.name "from GitHub Actions"
41+
git add --all
42+
git commit -m "build"
43+
git push
44+
fi

.github/workflows/touch.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: touch
2+
3+
on:
4+
schedule:
5+
- cron: '0 3 1 * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
touch:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Cache Composer packages
16+
id: composer-cache
17+
uses: actions/cache@v4
18+
with:
19+
path: vendor
20+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
21+
restore-keys: |
22+
${{ runner.os }}-php-
23+
24+
- name: Install dependencies
25+
run: composer install --prefer-dist --no-progress
26+
27+
- name: touch
28+
env:
29+
TZ: 'Asia/Tokyo'
30+
run: composer touch
31+
32+
- name: commit and push
33+
run: |
34+
git add -N .
35+
if ! git diff --exit-code --quiet
36+
then
37+
git config user.email "matsuoshi@gmail.com"
38+
git config user.name "from GitHub Actions"
39+
git add --all
40+
git commit -m "touch"
41+
git push
42+
fi

app/holidaysJP.php

+31-11
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public function generate()
4545
foreach ($yearly as $year => $a) {
4646
$this->generate_api_file($a, $year);
4747
}
48-
49-
$this->updateCheckedFile();
5048
}
5149

5250
/**
@@ -80,19 +78,47 @@ function get_holidays($data = null): Collection
8078
}
8179
$date = Chronos::createFromTimestamp(strtotime($m[1]));
8280

83-
// サマリ(祝日名)を求める
84-
if (preg_match('/SUMMARY:(.+?)\n/m', $event, $summary) != 1) {
81+
// 祝日名を取得
82+
$holiday_name = $this->get_holiday_name($event);
83+
if (!$holiday_name) {
8584
continue;
8685
}
8786

88-
$results[$date->timestamp] = $this->convert_holiday_name($date, $summary[1]);
87+
$results[$date->timestamp] = $this->convert_holiday_name($date, $holiday_name);
8988
}
9089

9190
// 日付順にソートして返却
9291
ksort($results);
9392
return Collection::make($results);
9493
}
9594

95+
public function get_holiday_name($event): ?string
96+
{
97+
if (preg_match('/SUMMARY:(.+?)\n/m', $event, $summary) != 1) {
98+
return null;
99+
};
100+
101+
return $this->filetr_holiday_name($summary[1]);
102+
}
103+
104+
public function filetr_holiday_name($name): ?string
105+
{
106+
$holidays = [
107+
'元日', '成人の日', '建国記念の日', '天皇誕生日',
108+
'春分の日', '昭和の日', '憲法記念日', 'みどりの日',
109+
'こどもの日', '海の日', '山の日', '敬老の日',
110+
'秋分の日', 'スポーツの日', '文化の日', '勤労感謝の日',
111+
'国民の休日', '祝日',
112+
// 過去の祝日
113+
'体育の日', '天皇の即位の日', '即位礼正殿の儀の行われる日',
114+
];
115+
foreach ($holidays as $holiday) {
116+
if (strpos($name, $holiday) !== false) {
117+
return $name;
118+
}
119+
}
120+
return null;
121+
}
96122

97123
/**
98124
* @param Chronos $date
@@ -184,10 +210,4 @@ protected function output_csv_file($filename, $data)
184210
}
185211
fclose($fp);
186212
}
187-
188-
protected function updateCheckedFile()
189-
{
190-
$checkedFile = self::DIST . '/checked_at.txt';
191-
file_put_contents($checkedFile, date('Y-m-d H:i:s'));
192-
}
193213
}

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"phpunit/phpunit": "^9.5"
1111
},
1212
"scripts": {
13-
"build": "php main.php",
13+
"build": "php main.php && composer touch",
14+
"touch": "date '+%F %T' > docs/v1/checked_at.txt",
1415
"test": "phpunit"
1516
}
1617
}

tests/data/2024.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"2024-01-01": "元日",
3+
"2024-01-08": "成人の日",
4+
"2024-02-11": "建国記念の日",
5+
"2024-02-12": "建国記念の日 振替休日",
6+
"2024-02-23": "天皇誕生日",
7+
"2024-03-20": "春分の日",
8+
"2024-04-29": "昭和の日",
9+
"2024-05-03": "憲法記念日",
10+
"2024-05-04": "みどりの日",
11+
"2024-05-05": "こどもの日",
12+
"2024-05-06": "こどもの日 振替休日",
13+
"2024-07-15": "海の日",
14+
"2024-08-11": "山の日",
15+
"2024-08-12": "休日 山の日",
16+
"2024-09-16": "敬老の日",
17+
"2024-09-22": "秋分の日",
18+
"2024-09-23": "秋分の日 振替休日",
19+
"2024-10-14": "スポーツの日",
20+
"2024-11-03": "文化の日",
21+
"2024-11-04": "文化の日 振替休日",
22+
"2024-11-23": "勤労感謝の日"
23+
}

tests/data/2025.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"2025-01-01": "元日",
3+
"2025-01-13": "成人の日",
4+
"2025-02-11": "建国記念の日",
5+
"2025-02-23": "天皇誕生日",
6+
"2025-02-24": "天皇誕生日 振替休日",
7+
"2025-03-20": "春分の日",
8+
"2025-04-29": "昭和の日",
9+
"2025-05-03": "憲法記念日",
10+
"2025-05-04": "みどりの日",
11+
"2025-05-05": "こどもの日",
12+
"2025-05-06": "みどりの日 振替休日",
13+
"2025-07-21": "海の日",
14+
"2025-08-11": "山の日",
15+
"2025-09-15": "敬老の日",
16+
"2025-09-23": "秋分の日",
17+
"2025-10-13": "スポーツの日",
18+
"2025-11-03": "文化の日",
19+
"2025-11-23": "勤労感謝の日",
20+
"2025-11-24": "勤労感謝の日 振替休日"
21+
}
File renamed without changes.

tests/holidaysJPTest.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class holidaysJPTest extends TestCase
1616
public function testICALAnalyze()
1717
{
1818
// サンプル ical データの解析テスト
19-
$test_file = __DIR__ . '/testdata.ics';
19+
$test_file = __DIR__ . '/data/testdata.ics';
2020
$holidays = new holidaysJP($test_file);
2121
$data = $holidays->get_holidays($holidays->get_ical_data());
2222

@@ -57,6 +57,15 @@ public function testGenerator()
5757
$this->checkApiFile("{$nextyear}/datetime.json", $nextyear, true);
5858
$this->checkApiFile("{$nextyear}/date.csv", $nextyear);
5959
$this->checkApiFile("{$nextyear}/datetime.csv", $nextyear, true);
60+
61+
// 2024/2025 ファイル一致チェック
62+
$file1 = file_get_contents(__DIR__ . '/data/2024.json');
63+
$file2 = file_get_contents(dirname(__DIR__) . '/docs/v1/2024/date.json');
64+
$this->assertEquals($file1, $file2);
65+
66+
$file1 = file_get_contents(__DIR__ . '/data/2025.json');
67+
$file2 = file_get_contents(dirname(__DIR__) . '/docs/v1/2025/date.json');
68+
$this->assertEquals($file1, $file2);
6069
}
6170

6271
/**

0 commit comments

Comments
 (0)