Code Monkey home page Code Monkey logo

between-dates's Introduction

Between Dates

Between dates is an API andpoint that can be used to calculate how many days, weekdays and complete weeks there are between 2 dates. It also accept extra parameters to have the results converted into seconds, minutes, hours or years.

Live endpoint

How to use it

Calling the API

  • Make a POST request to https://between-dates.herokuapp.com/between-dates sending a payload that contains startDate, endDate and format
    • startDate (optional):
      • ISO Date format: YYYY-MM-DDTHH:MM:SSZ or YYYY-MM-DD
      • The start date for the calculations. In case it's not provided, the system will use the current day as the start date.
    • endDate (mandatory):
      • ISO Date format: YYYY-MM-DDTHH:MM:SSZ or YYYY-MM-DD
      • The end date for the calculations
    • format (optional):
      • Possible values: seconds, minutes, hours or years
      • Provides extra properties in the response object with the completedWeeks, weekdays and days converted into the selected format.
  • To send different timezones, use the ISO datetime format YYYY-MM-DDTHH:MM:SSZ. The Z at the end defines the timezone.
    • Examples:
      • 2024-05-27T10:15:30-12:00
      • 2023-07-31T00:00:00+09:30

Examples

Get period without extra formats:

  • Request
{ 
	"startDate": "2022-08-03", 
	"endDate": "2024-05-27", 
	"format": "" 
}
  • Response
{
	"completeWeeks": 93,
	"weekdays": 472,
	"days": 662
}

Get period with extra formats:

  • Request
{ 
	"startDate": "2022-08-03", 
	"endDate": "2024-05-27", 
	"format": "seconds" 
}
  • Response
{
	"completeWeeks": 93,
	"weekdays": 472,
	"days": 662,
	"weekdaysInSeconds": "40780800 seconds",
	"completeWeeksInSeconds": "56246400 seconds",
	"daysInSeconds": "57196800 seconds"
}

Start and end date in different timezones

  • Request
{ 
	"startDate": "2022-08-03T10:15:30-12:30", 
	"endDate": "2024-05-27T10:15:30+12:30", 
	"format": "seconds" 
}
  • Response
{
	"completeWeeks": 92,
	"weekdays": 471,
	"days": 660,
	"weekdaysInSeconds": "40694400 seconds",
	"completeWeeksInSeconds": "55641600 seconds",
	"daysInSeconds": "57024000 seconds"
}

Implementation decisions

  • The system only accepts ISO Dates format as paramethers

    • YYYY-MM-DDTHH:MM:SSZ for datetime
    • YYYY-MM-DD for date
  • The startDate parameter is optional. In case it's null, the system will use the current date

  • The system uses luxon as date library because:

    • It's based on Moment which is known to be a powerful javascript date library.
    • It it well documented
    • After initial analysis it was concluded that it provides all functionalities required by th system
  • The system considers complete weeks starts on Mondays and ends on Sundays

  • The system only provides 2 decimal places for non integer values

Technologies used

  • API implementation: JavaScript, NodeJs, Express and luxon
  • Unit tests: C# and xUnit

System requirements

To run the system:

To run the unit tests:

Installation instructions

In your terminal:

  1. Clone git the repository:
git clone https://github.com/wagner-lopes/between-dates.git
  1. Open the repository folder
cd between-dates
  1. Install the System
npm install

Starting the express server

In your terminal

  1. Start the System
npm start

References

MIT License

License: MIT


@ 2022 Wagner Lopes

between-dates's People

Contributors

wagner-lopes avatar

Watchers

 avatar

between-dates's Issues

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.