Skip to content

picolino/isdayoff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

IsDayOff

Check-in CodeFactor Coverage Status Nuget NugetDownloads GitHub

IsDayOff is a .NET library for API isdayoff service (https://isdayoff.ru/)

Target Frameworks

DotNetStandard20

Quick start

To work with IsDayOff API you need only create IsDayOff class instance and call its methods. IsDayOff for .NET also provides useful configuration IsDayOffSettings for configure behaviour you need.

var defaultSettings = IsDayOffSettings.Default;
var settings = IsDayOffSettings.Build
                               .UseDefaultCountry(Country.USA)
                               .Create();

var isDayOff = new IsDayOff(settings);

var today = DateTime.Today;

DayType todayDayOffInfo = await isDayOff.CheckDayAsync(today);
List<DayOffDateTime> currentMonthDayOffInfo = await isDayOff.CheckMonthAsync(today.Year, today.Month);
List<DayOffDateTime> currentYearDayOffInfo = await isDayOff.CheckYearAsync(today.Year);

List<DayOffDateTime> currentYearDayOffInfoForRussia = await isDayOff.CheckYearAsync(today.Year, Country.Russia);

Default In-Memory Cache

IsDayOff for .NET provides built-in in-memory cache (disabled by-default)

var settings = IsDayOffSettings.Build
                               .UseInMemoryCache() // Enable cache
                               .Create();
var isDayOff = new IsDayOff(settings);
var firstRequest = await isDayOff.CheckDayAsync(DateTime.Today); // Performs request to external service
var secondRequest = await isDayOff.CheckDayAsync(DateTime.Today); // No request performs

It works also if you trying to get day off information for inner date range:

var firstRequestForYear = await isDayOff.CheckYearAsync(DateTime.Today.Year); // Performs request to external service for current year
var secondRequestForMonthWithinYear = await isDayOff.CheckMonthAsync(DateTime.Today.Year, 06); // No real request performs because year cache by previous request used

Custom cache implementation

You can also inject your custom cache realization through implementation of IIsDayOffCache interface and register it in settings:

var customCache = new CustomCache(); // CustomCache must implement IIsDayOffCache
var settings = IsDayOffSettings.Build
                               .UseCustomCache(customCache) // Inject cache
                               .Create();
var isDayOff = new IsDayOff(settings);

It is useful if you want to cache external service responses in file or in database.

Internal logging

This library provides additional trace logging.
You can enable logging through settings this way:

var settings = IsDayOffSettings.Build
                               .UseLogging(SourceLevels.All) // Enable debug logs and set required log level
                               .Create();
var isDayOff = new IsDayOff(settings);

Or you can enable and setup logging more flexible through default TraceSources configuration in *.config file of your application.
See docs for details.
TraceSource for all logs within IsDayOff library named as IsDayOff

FAQ

Q: Is this library fully thread safe?
A: Yes. You can use one instance between multiple threads with no doubt.

Q: Why some resources (urls) are not available through that library?
A: Because that functions built into .NET library or they can be created using already existing methods of library.

Here a full list of isdayoff resources that is not implemented in library and analogues that can be used to achieve similar behaviour:

isdayoff resource analogue
/now DateTime.Now
/today new IsDayOff().CheckDayAsync(DateTime.Today)
/tomorrow new IsDayOff().CheckDayAsync(DateTime.Today.AddDays(1))
/api/isleap?year=YYYY DateTime.IsLeapYear(YYYY)

License

MIT