https://github.com/wx257osn2/holiday_jp-cxx
Japanese holiday for C++20
https://github.com/wx257osn2/holiday_jp-cxx
Last synced: 3 months ago
JSON representation
Japanese holiday for C++20
- Host: GitHub
- URL: https://github.com/wx257osn2/holiday_jp-cxx
- Owner: wx257osn2
- License: mit
- Created: 2024-02-08T16:31:58.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-02-08T16:33:07.000Z (over 1 year ago)
- Last Synced: 2025-01-14T12:16:47.708Z (5 months ago)
- Language: C++
- Size: 8.79 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `holiday_jp-cxx`
Get holidays in Japan.
## Prerequisites
- C++20 supported compiler
## Install
This is header only library.
Just copy `include/*` in your include path.## Example
```cpp
#include"holiday_jp.hpp"
#include
#includeint main(){
using std::literals::chrono_literals::operator""y;
using std::literals::chrono_literals::operator""d;{
const auto from_date = 2023y/9/14d;
const auto to_date = 2023y/12/31d;
const auto holidays = holiday_jp::between(from_date, to_date);
std::cout << "Holiday(s) between " << from_date << " and " << to_date << ":\n";
for(auto&& [date, name] : holidays)
std::cout << "- " << date << ": " << name << '\n';
}{
const auto date = 2023y/8/11d;
const bool is_holiday = holiday_jp::is_holiday(date);
const auto holidays = holiday_jp::between(date, date);
std::cout << std::boolalpha << "Is " << date << " holiday?: " << is_holiday << " ("
<< (is_holiday ? holidays.begin()->name : "N/A") << ")" << std::endl;
}
}
```## API
```cpp
namespace holiday_jp{// Holiday data
struct holiday{
std::chrono::year_month_day date;
std::string_view name;
};// View of some holidays
template
class holidays_view{
public:
// Is the argument in the view?
constexpr bool contains(std::chrono::year_month_day)const;// Get the holiday name of the argument
// If the date is not in the view, this returns std::nullopt
constexpr std::optional operator[](std::chrono::year_month_day)const;// Range interface of the holidays
constexpr auto begin()const;
constexpr auto end()const;
constexpr auto size()const;// Get the new view from this view, between start to last
constexpr holidays_view<> between(std::chrono::year_month_day start, std::chrono::year_month_day last)const;
};// Holidays view of all holidays in Japan
static constexpr holidays_view holidays;// Check the date is holiday or not
static constexpr bool is_holiday(std::chrono::year_month_day date);// Get the holiday view between start to last
static constexpr holidays_view<> between(std::chrono::year_month_day start, std::chrono::year_month_day last);}
```## Development
### Prerequisites
- C++20 supported compiler
- `make`
- `git``git sumodule update --init --recursive` first.
### `make` commands for development
```console
$ make generate # generate include/stringized_holidays_yml.ipp from holiday_jp/holidays.yml
$ make test # test the API
$ make example # build example application
```