Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dates Concept Exercise (Library Fees) #1787

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions exercises/concept/library-fees/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Instructions

Your friend who works at a library in your city has asked you to extend her library software to automatically calculate late fees.

## 1. Determine if a book was checked out before noon

If a book was checked out before noon, the reader has 29 days to return it. If it was checked out at or after noon, it's 30 days.

```javascript
beforeNoon("2022-03-18T11:00:00")
// => false
```

## 2. Calculate the return date

Based on the checkout datetime, calculate the return date.

The fuction should return a `Date` object, either 29 or 30 days later.

```javascript
returnDate("2022-03-18T11:00:00")
// => Sun Apr 17 2022 11:00:00 GMT+0530 (India Standard Time)
```

_You need not worry about the time zone._

## 3. Determine how late the return of the book was

The library has a flat rate for late returns. To be able to calculate the fee, we need to know how many days after the return date the book was actually returned.

The library tracks both the date and time of the actual return of the book for statistical purposes, but doesn't use the time when calculating late fees.

```javascript
lateByDays("2022-04-17T11:00:00", "2022-03-24T11:00:00")
// => 7
```

## 4. Determine if the book was returned on a Monday

The library has a special offer for returning books on Mondays.

```javascript
returnOnMonday("2022-03-24T11:00:00")
// => false
```

## 5. Calculate the late fee

The library charges $0.50 per day if the book is returned late.

Your function should return the total late fee.

Include the special Monday offer. If you return the book on Monday, your late fee is off by 50%, rounded down.

```javascript
// TODO: Add Example
```
15 changes: 15 additions & 0 deletions exercises/concept/library-fees/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"root": true,
"extends": "@exercism/eslint-config-javascript",
"env": {
"jest": true
},
"overrides": [
{
"files": [".meta/proof.ci.js", ".meta/exemplar.js", "*.spec.js"],
"excludedFiles": ["custom.spec.js"],
"extends": "@exercism/eslint-config-javascript/maintainers"
}
]
}

3 changes: 3 additions & 0 deletions exercises/concept/library-fees/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
yarn-error.log

1 change: 1 addition & 0 deletions exercises/concept/library-fees/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
audit=false
21 changes: 21 additions & 0 deletions exercises/concept/library-fees/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Exercism

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions exercises/concept/library-fees/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: ['@exercism/babel-preset-javascript'],
plugins: [],
};

25 changes: 25 additions & 0 deletions exercises/concept/library-fees/meta/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Design

## Learning objectives

- how dates/timestamps are represented internally
- how to create dates with new Date, incl. some of the commonly used - variants
- `Date.parse()`
- `Date.now()`
- getting and setting the date components (`getMonth`/`setMonth` etc.)
- how to calculate a time difference
- how to compare dates

## Out of scope

- Introduction to Temporal
- Internationalization API
- Third party packages for handling dates

## Concepts

- `dates`

## Prerequisites

- `classes`
30 changes: 30 additions & 0 deletions exercises/concept/library-fees/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@exercism/javascript-freelancer-rates",
"description": "Exercism concept exercise on numbers",
"author": "Derk-Jan Karrenbeld <[email protected]>",
"private": true,
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/exercism/javascript",
"directory": "exercises/concept/freelancer-rates"
},
"devDependencies": {
"@babel/core": "^7.17.10",
"@exercism/babel-preset-javascript": "^0.1.2",
"@exercism/eslint-config-javascript": "^0.6.0",
"@types/jest": "^27.4.0",
"@types/node": "^16.11.35",
"babel-jest": "^28.1.0",
"core-js": "^3.22.5",
"eslint": "^8.15.0",
"jest": "^28.1.0"
},
"dependencies": {},
"scripts": {
"test": "jest ./*",
"watch": "jest --watch ./*",
"lint": "eslint ."
}
}