jpholiday

Crates.iojpholiday
lib.rsjpholiday
version0.1.4
sourcesrc
created_at2020-06-25 09:24:47.623614
updated_at2020-06-26 02:35:27.737954
descriptionJapan Public Holiday Generate for Rust
homepagehttps://github.com/Lalcs/jpholiday-rust
repositoryhttps://github.com/Lalcs/jpholiday-rust
max_upload_size
id257804
size48,914
(Lalcs)

documentation

README

JPHoliday

image image codecov

日本の祝日を取得するライブラリ

Usage

Cargo.tomlに追記

[dependencies]
jpholiday = "0.1"

Sample Code

指定日の祝日名を取得

use jpholiday::jpholiday::JPHoliday;
use jpholiday::chrono::{NaiveDate};
use std::borrow::Borrow;

let jpholiday = JPHoliday::new();

assert_eq!(
    jpholiday.is_holiday_name(NaiveDate::from_ymd(2017, 1, 1).borrow()).unwrap(),
    "元日".to_string()
);

assert_eq!(
    jpholiday.is_holiday_name(NaiveDate::from_ymd(2017, 1, 2).borrow()).unwrap(),
    "元日 振替休日".to_string()
);

assert_eq!(
    jpholiday.is_holiday_name(NaiveDate::from_ymd(2017, 1, 3).borrow()),
    None
);

指定日が祝日か判定

use jpholiday::jpholiday::JPHoliday;
use jpholiday::chrono::{NaiveDate};
use std::borrow::Borrow;

let jpholiday = JPHoliday::new();

assert_eq!(
    jpholiday.is_holiday(NaiveDate::from_ymd(2017, 1, 1).borrow()),
    true
);

assert_eq!(
    jpholiday.is_holiday(NaiveDate::from_ymd(2017, 1, 2).borrow()),
    true
);

assert_eq!(
    jpholiday.is_holiday(NaiveDate::from_ymd(2017, 1, 3).borrow()),
    false
);

指定年の祝日を取得

use jpholiday::jpholiday::JPHoliday;
use jpholiday::chrono::{NaiveDate};
use std::borrow::Borrow;

let jpholiday = JPHoliday::new();

assert_eq!(
    jpholiday.year_holidays(2017),
    vec![
        (NaiveDate::from_ymd(2017, 1, 1), "元日".to_string()),
        (NaiveDate::from_ymd(2017, 1, 2), "元日 振替休日".to_string()),
        (NaiveDate::from_ymd(2017, 1, 9), "成人の日".to_string()),
        (NaiveDate::from_ymd(2017, 2, 11), "建国記念の日".to_string()),
        (NaiveDate::from_ymd(2017, 3, 20), "春分の日".to_string()),
        (NaiveDate::from_ymd(2017, 4, 29), "昭和の日".to_string()),
        (NaiveDate::from_ymd(2017, 5, 3), "憲法記念日".to_string()),
        (NaiveDate::from_ymd(2017, 5, 4), "みどりの日".to_string()),
        (NaiveDate::from_ymd(2017, 5, 5), "こどもの日".to_string()),
        (NaiveDate::from_ymd(2017, 7, 17), "海の日".to_string()),
        (NaiveDate::from_ymd(2017, 8, 11), "山の日".to_string()),
        (NaiveDate::from_ymd(2017, 9, 18), "敬老の日".to_string()),
        (NaiveDate::from_ymd(2017, 9, 23), "秋分の日".to_string()),
        (NaiveDate::from_ymd(2017, 10, 9), "体育の日".to_string()),
        (NaiveDate::from_ymd(2017, 11, 3), "文化の日".to_string()),
        (NaiveDate::from_ymd(2017, 11, 23), "勤労感謝の日".to_string()),
        (NaiveDate::from_ymd(2017, 12, 23), "天皇誕生日".to_string())
    ]
);

指定月の祝日を取得

use jpholiday::jpholiday::JPHoliday;
use jpholiday::chrono::{NaiveDate};
use std::borrow::Borrow;

let jpholiday = JPHoliday::new();

assert_eq!(
    jpholiday.month_holidays(2017, 5),
    vec![
        (NaiveDate::from_ymd(2017, 5, 3), "憲法記念日".to_string()),
        (NaiveDate::from_ymd(2017, 5, 4), "みどりの日".to_string()),
        (NaiveDate::from_ymd(2017, 5, 5), "こどもの日".to_string())
    ]
);

指定範囲の祝日を取得

use jpholiday::jpholiday::JPHoliday;
use jpholiday::chrono::{NaiveDate};
use std::borrow::Borrow;

let jpholiday = JPHoliday::new();

assert_eq!(
    jpholiday.between(NaiveDate::from_ymd(2017, 1, 1).borrow(), NaiveDate::from_ymd(2017, 5, 3).borrow()),
    vec![
        (NaiveDate::from_ymd(2017, 1, 1), "元日".to_string()),
        (NaiveDate::from_ymd(2017, 1, 2), "元日 振替休日".to_string()),
        (NaiveDate::from_ymd(2017, 1, 9), "成人の日".to_string()),
        (NaiveDate::from_ymd(2017, 2, 11), "建国記念の日".to_string()),
        (NaiveDate::from_ymd(2017, 3, 20), "春分の日".to_string()),
        (NaiveDate::from_ymd(2017, 4, 29), "昭和の日".to_string()),
        (NaiveDate::from_ymd(2017, 5, 3), "憲法記念日".to_string())
    ]
);
Commit count: 24

cargo fmt