Skip to content

Cloud-ready customizable project for calculating business days, holidays, and work schedules.

License

Notifications You must be signed in to change notification settings

lifenture/businesscalendar

Repository files navigation

Business Calendar Function

AWS Lambda function for calculating business days considering regional holidays and working days patterns.

Features

  • Calculate business days across different regions
  • Support for various working week patterns:
    • Monday-Friday (standard)
    • Sunday-Thursday (Middle East)
    • Monday-Saturday (Nepal)
  • Skip regional holidays using Jollyday library
  • ISO 3166-1 alpha-2 country code validation
  • JSON request/response format

Prerequisites

  • Java 21 (minimum required version)
  • Gradle 8.14.2
  • AWS Lambda runtime

Building

Build the project using Gradle:

./gradlew clean build

To build and package the Lambda function:

./gradlew packageLambda

This will create the deployment package at app/build/dist/function.zip. The ZIP contains all class files and dependencies extracted directly into the archive (not as a nested JAR), which is the correct format for AWS Lambda deployment.

Testing

Run the test suite:

./gradlew test

Usage

Request Format

{
  "startDate": "2025-06-13",
  "daysToAdd": 5,
  "countryCode": "US"
}

Response Format

{
  "resultDate": "2025-06-20"
}

Example Usage

Calculate business days for Israel (Sunday-Thursday work week):

curl -X POST https://your-api-gateway-url/prod/business-calendar \
  -H "Content-Type: application/json" \
  -d '{"startDate":"2025-06-12","daysToAdd":3,"countryCode":"IL"}'

Error Handling

  • 400 Bad Request: Invalid parameters or country code
  • 500 Internal Server Error: Processing errors

Deployment

Deploy the ZIP to AWS Lambda using one of these options:

1. AWS Lambda Console (Manual)

  1. Go to the AWS Lambda console
  2. Create a new function or select an existing one
  3. In the "Function code" section:
    • Choose "Upload from .zip file"
    • Upload the app/build/dist/function.zip file
    • Save changes

2. AWS CLI (Automated)

aws lambda create-function \
  --function-name business-calendar \
  --runtime java21 \
  --handler com.lifenture.functions.BusinessCalendarHandler::handleRequest \
  --role arn:aws:iam::123456789012:role/lambda-role \
  --zip-file fileb://app/build/dist/function.zip

To update an existing function:

aws lambda update-function-code \
  --function-name business-calendar \
  --zip-file fileb://app/build/dist/function.zip

Note: Replace these values with your configuration:

  • 123456789012: Your AWS account ID
  • lambda-role: Your Lambda execution role

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes using conventional commits
  4. Push to the branch
  5. Create a Pull Request

Credits

This project uses the following open-source libraries:

Jollyday

Holiday calculation is powered by Jollyday, a Java library for handling holidays.

  • Project: focus-shift/jollyday
  • License: Apache License 2.0
  • Authors:
    • Sven Diedrichsen (Original author)
    • Focus Shift Team (Current maintainers)
      • Marcel Dix
      • Matthias Born
      • Andreas Dangel
      • Michael Bowler

Special thanks to the Jollyday team for providing and maintaining this excellent holiday calculation library.

License License: MIT

This project is licensed under the MIT License - see the LICENSE file for details.

It uses third-party libraries, including components licensed under the Apache License, Version 2.0.