Code Monkey home page Code Monkey logo

workingday-temporal-adjusters's Introduction

##평일/휴일 계산 - Workingday TemporalAdjusters

####jdk8에서 사용하고 있는 java.time을 사용한 평일/공휴일 계산하는 TemporalAdjuster

  • 추가 공휴일 없이 주말만으로 평일/공휴일 계산할때 WorkingDayTemporalAdjusters.onlyWeekEnd()

@Test
public void onlyWeekEnd() throws Exception {
    WorkingDayTemporalAdjusters adjusters = WorkingDayTemporalAdjusters.onlyWeekEnd();
    
    LocalDate friday = LocalDate.of(2017, 9, 29);
    
    LocalDate saturday = friday.with(adjusters.nextHoliday());
    assertEquals(LocalDate.of(2017, 9, 30), friday.with(adjusters.nextHoliday()));
    
    
    LocalDate monday = friday.with(adjusters.nextWorkingDay());
    assertEquals(LocalDate.of(2017, 10, 2), monday);

    LocalDate thursday = friday.with(adjusters.previousWorkingDay());
    assertEquals(LocalDate.of(2017, 9, 28), thursday);
    
    LocalDate sunday = friday.with(adjusters.previousHoliday());
    assertEquals(LocalDate.of(2017, 9, 24), sunday);
}

  • 추가 공휴일을 등록하고 평일/공휴일을 계산할때 WorkingDayTemporalAdjusters.withHolidays(Holidays holidays)

@Test
public void withHolidays() throws Exception {
    WorkingDayTemporalAdjusters adjusters = WorkingDayTemporalAdjusters.withHolidays(
        Holidays.of(
            asList(
                LocalDate.of(2017, 10, 3),//the National foundation Day
                LocalDate.of(2017, 10, 4),//Korean Thanksgiving Day
                LocalDate.of(2017, 10, 5),//Korean Thanksgiving Day
                LocalDate.of(2017, 10, 6),//Korean Thanksgiving Day
                LocalDate.of(2017, 10, 9) //Hangul Day
            )
        )
    );
    
    LocalDate monday = LocalDate.of(2017, 10, 2);
    
    LocalDate nationalFoundationDay = monday.with(adjusters.nextHoliday());
    assertEquals(LocalDate.of(2017, 10, 3), nationalFoundationDay);
    
    LocalDate nextDay = monday.with(adjusters.nextWorkingDay());
    assertEquals(LocalDate.of(2017, 10, 10), nextDay);
    
    LocalDate previousDay = monday.with(adjusters.previousWorkingDay());
    assertEquals(LocalDate.of(2017, 9, 29), previousDay);
    
    LocalDate sunday = monday.with(adjusters.previousHoliday());
    assertEquals(LocalDate.of(2017, 10, 1), sunday);
}

workingday-temporal-adjusters's People

Watchers

 avatar  avatar

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.