| Crates.io | holidays_jp |
| lib.rs | holidays_jp |
| version | 0.3.1 |
| created_at | 2023-02-18 01:33:59.253959+00 |
| updated_at | 2025-10-20 13:52:58.103103+00 |
| description | holidays_jp determines Japanese national holiday. The definition of holidays is based on csv file provided by the Cabinet Office. |
| homepage | |
| repository | https://github.com/nabetama/holidays_jp |
| max_upload_size | |
| id | 787936 |
| size | 90,984 |
holidays_jp is both a Rust library and command-line tool for determining Japanese national holidays. It provides a simple and efficient way to check if specific dates are holidays, list holidays within date ranges, and manage holiday data.
The holiday data is based on the official CSV file provided by the Cabinet Office of Japan. The data is automatically updated once a week via GitHub Actions, ensuring you always have the latest holiday information.
Note: The data source URL is configurable via
config.toml. See the configuration section for details.
Add this to your Cargo.toml:
[dependencies]
holidays_jp = "0.3"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
git clone https://github.com/nabetama/holidays_jp.git
cd holidays_jp
cargo build --release
cargo install holidays_jp
use holidays_jp::{HolidayService, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the service with default configuration
let config = Config::default();
let mut service = HolidayService::new(config);
service.initialize().await?;
// Check if a specific date is a holiday
let (is_holiday, holiday_name) = service.get_holiday("2023-01-01")?;
if is_holiday {
println!("2023-01-01 is a holiday: {}", holiday_name.unwrap());
} else {
println!("2023-01-01 is not a holiday");
}
Ok(())
}
use holidays_jp::{HolidayService, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::default();
let mut service = HolidayService::new(config);
service.initialize().await?;
// Get all holidays in 2023
let holidays = service.get_holidays_in_range("2023-01-01", "2023-12-31")?;
for (date, name) in holidays {
println!("{}: {}", date, name);
}
Ok(())
}
If your PC is connected to the Internet, you can obtain the latest Japanese national holiday data by executing the following command.
cargo run -- update
# Check today's date (default behavior)
holidays_jp
20251014 is not a holiday
# Check a specific date (with -d option)
holidays_jp check -d 20220101
20220101 is holiday(元日)
# Check a specific date (positional argument, no -d required)
holidays_jp check 20220101
20220101 is holiday(元日)
# Check with different date format
holidays_jp check 2022/01/01
2022/01/01 is holiday(元日)
# JSON output for scripting
holidays_jp check 2022-01-01 -o json
{"date":"2022-01-01","is_holiday":true,"holiday_name":"元日"}
# Quiet output (holiday name only)
holidays_jp check 2022-01-01 -o quiet
元日
# Verbose output with additional information
holidays_jp check 2022-01-01 -v
Checking date: 2022-01-01
Configuration loaded successfully
Holiday data loaded: 123 holidays
2022-01-01 is holiday(元日)
# List holidays in January 2023
holidays_jp list --start 2023-01-01 --end 2023-01-31
Holidays in range (2023-01-01 to 2023-01-31):
2023-01-01 - 元日
2023-01-02 - 休日
2023-01-09 - 成人の日
# JSON output for programmatic use
holidays_jp list --start 2023-01-01 --end 2023-01-31 -o json
{
"start_date": "2023-01-01",
"end_date": "2023-01-31",
"holidays": [
{
"date": "2023-01-01",
"is_holiday": true,
"holiday_name": "元日"
},
{
"date": "2023-01-02",
"is_holiday": true,
"holiday_name": "休日"
},
{
"date": "2023-01-09",
"is_holiday": true,
"holiday_name": "成人の日"
}
]
}
# List all holidays in 2023
holidays_jp list --start 2023/01/01 --end 2023/12/31
# Update to the latest holiday data
holidays_jp update
🔄 Updating holiday data from official source...
✅ Holiday data updated successfully!
# General help
holidays_jp --help
# Command-specific help
holidays_jp check --help
holidays_jp list --help
holidays_jp update --help
The tool automatically detects and supports various date formats:
YYYYMMDD (e.g., 20230101)YYYY-MM-DD (e.g., 2023-01-01)YYYY/MM/DD (e.g., 2023/01/01)YYYY年MM月DD日 (e.g., 2023年1月1日)MM/DD/YYYY (e.g., 01/01/2023)DD/MM/YYYY (e.g., 01/01/2023)YYYY.MM.DD (e.g., 2023.01.01)The application automatically generates a config.toml file on first run with default settings. You can customize this file to fit your needs.
config.toml (created automatically on first run)config.toml.example (reference configuration with detailed comments)[holiday_data]
# Data source URL (configurable)
source_url = "https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv"
# Cache file location
cache_file = "./data/holidays.json"
[cache]
# Cache strategy: TimeBased, EtagBased, Hybrid, AlwaysRefresh, NeverRefresh
strategy = "Hybrid"
# Maximum cache age in hours (default: 168 = 7 days)
max_age_hours = 168
# ETag check interval in hours (default: 24 = 1 day)
etag_check_interval_hours = 24
# Force refresh on startup
force_refresh_on_startup = false
Note: All default configuration values are defined in
src/constants.rs. When you first run the application, it will createconfig.tomlwith these defaults. You can then modifyconfig.tomlto customize the behavior without changing the source code.
You can use custom holiday data sources by modifying the source_url in config.toml. The CSV format should match the official format:
日付,祝日名
2023/1/1,元日
2023/1/2,休日
...