From 38a685045ff11a666c1f6e8dc18da9b9270092c1 Mon Sep 17 00:00:00 2001 From: matsuoshi Date: Mon, 9 Sep 2024 16:47:18 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=20-=202024/2025=20=E7=A5=9D=E6=97=A5=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E4=B8=80=E8=87=B4=E3=83=81=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=82=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/data/2024.json | 23 +++++++++++++++++++++++ tests/data/2025.json | 21 +++++++++++++++++++++ tests/{ => data}/testdata.ics | 0 tests/holidaysJPTest.php | 11 ++++++++++- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/data/2024.json create mode 100644 tests/data/2025.json rename tests/{ => data}/testdata.ics (100%) diff --git a/tests/data/2024.json b/tests/data/2024.json new file mode 100644 index 0000000..81abafc --- /dev/null +++ b/tests/data/2024.json @@ -0,0 +1,23 @@ +{ + "2024-01-01": "元日", + "2024-01-08": "成人の日", + "2024-02-11": "建国記念の日", + "2024-02-12": "建国記念の日 振替休日", + "2024-02-23": "天皇誕生日", + "2024-03-20": "春分の日", + "2024-04-29": "昭和の日", + "2024-05-03": "憲法記念日", + "2024-05-04": "みどりの日", + "2024-05-05": "こどもの日", + "2024-05-06": "こどもの日 振替休日", + "2024-07-15": "海の日", + "2024-08-11": "山の日", + "2024-08-12": "休日 山の日", + "2024-09-16": "敬老の日", + "2024-09-22": "秋分の日", + "2024-09-23": "秋分の日 振替休日", + "2024-10-14": "スポーツの日", + "2024-11-03": "文化の日", + "2024-11-04": "文化の日 振替休日", + "2024-11-23": "勤労感謝の日" +} \ No newline at end of file diff --git a/tests/data/2025.json b/tests/data/2025.json new file mode 100644 index 0000000..2014d1d --- /dev/null +++ b/tests/data/2025.json @@ -0,0 +1,21 @@ +{ + "2025-01-01": "元日", + "2025-01-13": "成人の日", + "2025-02-11": "建国記念の日", + "2025-02-23": "天皇誕生日", + "2025-02-24": "天皇誕生日 振替休日", + "2025-03-20": "春分の日", + "2025-04-29": "昭和の日", + "2025-05-03": "憲法記念日", + "2025-05-04": "みどりの日", + "2025-05-05": "こどもの日", + "2025-05-06": "みどりの日 振替休日", + "2025-07-21": "海の日", + "2025-08-11": "山の日", + "2025-09-15": "敬老の日", + "2025-09-23": "秋分の日", + "2025-10-13": "スポーツの日", + "2025-11-03": "文化の日", + "2025-11-23": "勤労感謝の日", + "2025-11-24": "勤労感謝の日 振替休日" +} \ No newline at end of file diff --git a/tests/testdata.ics b/tests/data/testdata.ics similarity index 100% rename from tests/testdata.ics rename to tests/data/testdata.ics diff --git a/tests/holidaysJPTest.php b/tests/holidaysJPTest.php index fc88ef2..86be087 100644 --- a/tests/holidaysJPTest.php +++ b/tests/holidaysJPTest.php @@ -16,7 +16,7 @@ class holidaysJPTest extends TestCase public function testICALAnalyze() { // サンプル ical データの解析テスト - $test_file = __DIR__ . '/testdata.ics'; + $test_file = __DIR__ . '/data/testdata.ics'; $holidays = new holidaysJP($test_file); $data = $holidays->get_holidays($holidays->get_ical_data()); @@ -57,6 +57,15 @@ public function testGenerator() $this->checkApiFile("{$nextyear}/datetime.json", $nextyear, true); $this->checkApiFile("{$nextyear}/date.csv", $nextyear); $this->checkApiFile("{$nextyear}/datetime.csv", $nextyear, true); + + // 2024/2025 ファイル一致チェック + $file1 = file_get_contents(__DIR__ . '/data/2024.json'); + $file2 = file_get_contents(dirname(__DIR__) . '/docs/v1/2024/date.json'); + $this->assertEquals($file1, $file2); + + $file1 = file_get_contents(__DIR__ . '/data/2025.json'); + $file2 = file_get_contents(dirname(__DIR__) . '/docs/v1/2025/date.json'); + $this->assertEquals($file1, $file2); } /** From 0eabd5413de0b1d97c285beea0ff8bc669057673 Mon Sep 17 00:00:00 2001 From: matsuoshi Date: Mon, 9 Sep 2024 16:48:25 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E7=A5=9D=E6=97=A5=E3=81=AE=E3=81=BF?= =?UTF-8?q?=E3=82=92=E6=8A=BD=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/holidaysJP.php | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/app/holidaysJP.php b/app/holidaysJP.php index 8177e0f..b353864 100644 --- a/app/holidaysJP.php +++ b/app/holidaysJP.php @@ -80,12 +80,13 @@ function get_holidays($data = null): Collection } $date = Chronos::createFromTimestamp(strtotime($m[1])); - // サマリ(祝日名)を求める - if (preg_match('/SUMMARY:(.+?)\n/m', $event, $summary) != 1) { + // 祝日名を取得 + $holiday_name = $this->get_holiday_name($event); + if (!$holiday_name) { continue; } - $results[$date->timestamp] = $this->convert_holiday_name($date, $summary[1]); + $results[$date->timestamp] = $this->convert_holiday_name($date, $holiday_name); } // 日付順にソートして返却 @@ -93,6 +94,33 @@ function get_holidays($data = null): Collection return Collection::make($results); } + public function get_holiday_name($event): ?string + { + if (preg_match('/SUMMARY:(.+?)\n/m', $event, $summary) != 1) { + return null; + }; + + return $this->filetr_holiday_name($summary[1]); + } + + public function filetr_holiday_name($name): ?string + { + $holidays = [ + '元日', '成人の日', '建国記念の日', '天皇誕生日', + '春分の日', '昭和の日', '憲法記念日', 'みどりの日', + 'こどもの日', '海の日', '山の日', '敬老の日', + '秋分の日', 'スポーツの日', '文化の日', '勤労感謝の日', + '国民の休日', '祝日', + // 過去の祝日 + '体育の日', '天皇の即位の日', '即位礼正殿の儀の行われる日', + ]; + foreach ($holidays as $holiday) { + if (strpos($name, $holiday) !== false) { + return $name; + } + } + return null; + } /** * @param Chronos $date From f29e0ed9826fee9a43697c3f00690c2e6c79a9d2 Mon Sep 17 00:00:00 2001 From: matsuoshi Date: Mon, 9 Sep 2024 16:50:54 +0900 Subject: [PATCH 3/3] =?UTF-8?q?build=20(=E6=AF=8E=E5=B9=B4)=E3=81=A8=20tou?= =?UTF-8?q?ch=20(=E6=AF=8E=E6=9C=88)=20=E3=81=A7=20GitHub=20Actions=20?= =?UTF-8?q?=E3=82=92=E5=88=86=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 20 +++++++++--------- .github/workflows/touch.yml | 42 +++++++++++++++++++++++++++++++++++++ app/holidaysJP.php | 8 ------- composer.json | 3 ++- 4 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/touch.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index faa62e5..7a257e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,22 +1,22 @@ -name: PHP Composer +name: Build on: - push: - branches: [ master, v1.1, build-test ] schedule: - - cron: '5 15 1,31 * *' + - cron: '0 15 31 12 *' + workflow_dispatch: + push: + branches: [ build-test ] jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Cache Composer packages id: composer-cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: vendor key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} @@ -27,11 +27,11 @@ jobs: run: composer install --prefer-dist --no-progress - name: build api files + env: + TZ: 'Asia/Tokyo' run: composer build - name: commit and push - env: - TZ: 'Asia/Tokyo' run: | git add -N . if ! git diff --exit-code --quiet @@ -39,6 +39,6 @@ jobs: git config user.email "matsuoshi@gmail.com" git config user.name "from GitHub Actions" git add --all - git commit -m "$(date +'%Y-%m-%d %H:%M:%S')" + git commit -m "build" git push fi diff --git a/.github/workflows/touch.yml b/.github/workflows/touch.yml new file mode 100644 index 0000000..9f80891 --- /dev/null +++ b/.github/workflows/touch.yml @@ -0,0 +1,42 @@ +name: touch + +on: + schedule: + - cron: '0 3 1 * *' + workflow_dispatch: + +jobs: + touch: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: touch + env: + TZ: 'Asia/Tokyo' + run: composer touch + + - name: commit and push + run: | + git add -N . + if ! git diff --exit-code --quiet + then + git config user.email "matsuoshi@gmail.com" + git config user.name "from GitHub Actions" + git add --all + git commit -m "touch" + git push + fi diff --git a/app/holidaysJP.php b/app/holidaysJP.php index b353864..8b6268e 100644 --- a/app/holidaysJP.php +++ b/app/holidaysJP.php @@ -45,8 +45,6 @@ public function generate() foreach ($yearly as $year => $a) { $this->generate_api_file($a, $year); } - - $this->updateCheckedFile(); } /** @@ -212,10 +210,4 @@ protected function output_csv_file($filename, $data) } fclose($fp); } - - protected function updateCheckedFile() - { - $checkedFile = self::DIST . '/checked_at.txt'; - file_put_contents($checkedFile, date('Y-m-d H:i:s')); - } } diff --git a/composer.json b/composer.json index c3fb47a..48b5fa1 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "phpunit/phpunit": "^9.5" }, "scripts": { - "build": "php main.php", + "build": "php main.php && composer touch", + "touch": "date '+%F %T' > docs/v1/checked_at.txt", "test": "phpunit" } }