diff --git a/exercises/concept/library-fees/.docs/instructions.md b/exercises/concept/library-fees/.docs/instructions.md new file mode 100644 index 0000000000..7686c1fd03 --- /dev/null +++ b/exercises/concept/library-fees/.docs/instructions.md @@ -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 +``` \ No newline at end of file diff --git a/exercises/concept/library-fees/.eslintrc b/exercises/concept/library-fees/.eslintrc new file mode 100644 index 0000000000..310d7072df --- /dev/null +++ b/exercises/concept/library-fees/.eslintrc @@ -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" + } + ] + } + \ No newline at end of file diff --git a/exercises/concept/library-fees/.gitignore b/exercises/concept/library-fees/.gitignore new file mode 100644 index 0000000000..bdb912f98a --- /dev/null +++ b/exercises/concept/library-fees/.gitignore @@ -0,0 +1,3 @@ +node_modules +yarn-error.log + diff --git a/exercises/concept/library-fees/.npmrc b/exercises/concept/library-fees/.npmrc new file mode 100644 index 0000000000..d26df800bb --- /dev/null +++ b/exercises/concept/library-fees/.npmrc @@ -0,0 +1 @@ +audit=false diff --git a/exercises/concept/library-fees/LICENSE b/exercises/concept/library-fees/LICENSE new file mode 100644 index 0000000000..90e73be03b --- /dev/null +++ b/exercises/concept/library-fees/LICENSE @@ -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. diff --git a/exercises/concept/library-fees/babel.config.js b/exercises/concept/library-fees/babel.config.js new file mode 100644 index 0000000000..177a798151 --- /dev/null +++ b/exercises/concept/library-fees/babel.config.js @@ -0,0 +1,5 @@ +module.exports = { + presets: ['@exercism/babel-preset-javascript'], + plugins: [], + }; + \ No newline at end of file diff --git a/exercises/concept/library-fees/meta/design.md b/exercises/concept/library-fees/meta/design.md new file mode 100644 index 0000000000..2a5f247bd9 --- /dev/null +++ b/exercises/concept/library-fees/meta/design.md @@ -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` diff --git a/exercises/concept/library-fees/package.json b/exercises/concept/library-fees/package.json new file mode 100644 index 0000000000..9c7a423b4b --- /dev/null +++ b/exercises/concept/library-fees/package.json @@ -0,0 +1,30 @@ +{ + "name": "@exercism/javascript-freelancer-rates", + "description": "Exercism concept exercise on numbers", + "author": "Derk-Jan Karrenbeld ", + "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 ." + } + } + \ No newline at end of file