Git Product home page Git Product logo

bizdays's Introduction

BizDays Build Status

Java date and time calculator for operations on business days and working time such as:

  • check if a date is a business day or a holiday,
  • get next business day,
  • get business day after (before) a given date,
  • count business days between given dates,
  • add (subtract) business days to (from) a given date,
  • check if given time is working time,
  • next EOD, next EOD after (before) given time,
  • add (subtract) working hours to given time.

Project structure

...
├── calendar                     # business days
│   ├── BusinessCalendar
│   ├── BusinessCalendarFactory  # factory for national business calendars
│   └── ...                      # place for national business calendar implementations
├── holiday                      # holiday definitions
│   ├── CronHoliday
│   ├── EasterBasedHoliday
│   ├── FixedYearlyHoliday
│   ├── Holiday
│   ├── MovableYearlyHoliday
│   └── YearlyHoliday
├── schedule                     # work time 
│   ├── BusinessDay              # start/end of work time
│   └── BusinessSchedule         # BusinessTimeCalculator implementation
├── BusinessDayCalculator        # business days methods
└── BusinessTimeCalculator       # business time methods

Examples

Business days operations

BusinessCalendarFactory factory = new AmericanBusinessCalendarFactory();
BusinessCalendar calendar = factory.getInstance();

LocalDate nbd = calendar.nextBusinessDay();
LocalDate next5Days = calendar.plus(LocalDate.now(), 5);
int workingDays2016 = calendar.businessDaysBetween(LocalDate.of(2016, 1, 1), LocalDate.of(2016, 12, 31));

Work time operations

BusinessSchedule schedule = new BusinessSchedule(calendar);
        
boolean workNow = schedule.isBusinessTime(LocalDateTime.now());
LocalDateTime next16h = schedule.plus(LocalDateTime.now(), 16);
LocalDateTime next15min = schedule.plus(LocalDateTime.now(), Duration.ofMinutes(15));

Custom business calendar

BusinessCalendar calendar = new BusinessCalendar();
calendar.addHoliday(CronHoliday.SATURDAY);
calendar.addHoliday(CronHoliday.SUNDAY);
calendar.addHoliday(FixedYearlyHoliday.NEW_YEAR);
calendar.addHoliday(FixedYearlyHoliday.CHRISTMAS);
calendar.addHoliday(EasterBasedHoliday.EASTER);
calendar.addHoliday(EasterBasedHoliday.EASTER_MONDAY);

// Valentine's Day
calendar.addHoliday(new FixedYearlyHoliday(Month.FEBRUARY, 14));
// and every first thursday in month
calendar.addHoliday(new CronHoliday("* * * ? * THU#1 *"));

Custom business schedule

Let's assume that your company works from 7am to 3pm except fridays, when it starts at 9am and closes at 2pm.

BusinessSchedule schedule = new BusinessSchedule(calendar);
schedule.setDefaultBusinessDay(new BusinessDay(LocalTime.of(7, 0), LocalTime.of(15, 0)));
schedule.putBusinessDay(DayOfWeek.FRIDAY, new BusinessDay(9, 0, 14, 0));

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.