Giter Site home page Giter Site logo

picolino / isdayoff Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 2.0 207 KB

IsDayOff API for .NET

Home Page: https://isdayoff.ru

License: MIT License

C# 100.00%
isdayoff holidays holidays-api workday workdays workday-api workday-webservice datetime daily dotnet

isdayoff's Introduction

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

isdayoff's People

Contributors

picolino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

isdayoff's Issues

AddWorkDays

Добрый день.

1.Вопрос можно ли сделать Sync методы ?
2.Можно ли адаптировать данную библиотеку для 4,8 net ?
3. Можно ли сделать функцию которая бы на входе давала 2 параметра.
1 параметр дата, 2 параметр количество рабочих дней, возвращаемое значение Дата.
Функция называется AddWorkDays.

[BUG] CheckMonthAsync fails with exception

🐛 Bug Report

Environment: .NET Core 3.1

Method CheckMonthAsync of IsDayOff fails with exception:
System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
at System.DateTime..ctor(Int32 year, Int32 month, Int32 day)
at isdayoff.IsDayOff.CheckMonthAsync(Int32 year, Int32 month, Country country, CancellationToken cancellationToken)
at isdayoff.IsDayOff.CheckMonthAsync(Int32 year, Int32 month, CancellationToken cancellationToken)
at isdayoff.IsDayOff.CheckMonthAsync(Int32 year, Int32 month)

I looked code and noticed that DateTime inside is created with day = 0.
It's incorrect day for DateTime so code fails.

Expected behavior

Code works normally without exception.

Reproduction steps

Code inside some async method:

var settings = IsDayOffSettings.Build
    .UseDefaultCountry(Country.Russia)
    .Create();

var isDayOff = new IsDayOff(settings);

var today = DateTime.UtcNow;

// here code fails with exception
var days = await isDayOff.CheckMonthAsync(today.Year, today.Month);

Version: 1.3.0

Testing

Hi
Using your library, I ran into a testing problem.
Specifically, I wanted to mock your service. Okay, let's say there is no interface, but then why are the methods not virtual?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.