Crates.io | jpholiday |
lib.rs | jpholiday |
version | 0.1.4 |
source | src |
created_at | 2020-06-25 09:24:47.623614 |
updated_at | 2020-06-26 02:35:27.737954 |
description | Japan Public Holiday Generate for Rust |
homepage | https://github.com/Lalcs/jpholiday-rust |
repository | https://github.com/Lalcs/jpholiday-rust |
max_upload_size | |
id | 257804 |
size | 48,914 |
日本の祝日を取得するライブラリ
Cargo.toml
に追記
[dependencies]
jpholiday = "0.1"
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())
]
);