Skip to content

Add swift-scheduling exercise #2536

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

Merged
merged 19 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
133 changes: 133 additions & 0 deletions exercises/swift-scheduling/canonical-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"exercise": "swift-scheduling",
"comments": [
"The dates are formatted per ",
"https://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15.",
"",
"Tracks that support changing the system's current time can consider ",
"setting the system's current time to the meeting start instead of ",
"passing it as an argument."
],
"cases": [
{
"uuid": "1d0e6e72-f370-408c-bc64-5dafa9c6da73",
"description": "NOW translates to two hours later",
"property": "deliveryDate",
"input": {
"meetingStart": "2012-02-13T09:00:00",
"description": "NOW"
},
"expected": "2012-02-13T11:00:00"
},
{
"uuid": "93325e7b-677d-4d96-b017-2582af879dc2",
"description": "ASAP before noon translates to today at five in the afternoon",
"property": "deliveryDate",
"input": {
"meetingStart": "1999-06-03T09:45:00",
"description": "ASAP"
},
"expected": "1999-06-03T17:00:00"
},
{
"uuid": "6fddc1ea-2fe9-4c60-81f7-9220d2f45537",
"description": "ASAP after noon translates to tomorrow at noon",
"property": "deliveryDate",
"input": {
"meetingStart": "2008-12-21T13:30:00",
"description": "ASAP"
},
"expected": "2008-12-22T12:00:00"
},
{
"uuid": "25f46bf9-6d2a-4e95-8edd-f62dd6bc8a6e",
"description": "EOW on Monday translates to Friday at five in the afternoon",
"property": "deliveryDate",
"input": {
"meetingStart": "2025-02-03T00:00:00",
"description": "EOW"
},
"expected": "2025-02-07T17:00:00"
},
{
"uuid": "0b375df5-d198-489e-acee-fd538a768616",
"description": "EOW on Tuesday translates to Friday at five in the afternoon",
"property": "deliveryDate",
"input": {
"meetingStart": "1997-04-29T00:00:00",
"description": "EOW"
},
"expected": "1997-05-02T17:00:00"
},
{
"uuid": "4afbb881-0b5c-46be-94e1-992cdc2a8ca4",
"description": "EOW on Wednesday translates to Friday at five in the afternoon",
"property": "deliveryDate",
"input": {
"meetingStart": "2005-09-14T00:00:00",
"description": "EOW"
},
"expected": "2005-09-16T17:00:00"
},
{
"uuid": "e1341c2b-5e1b-4702-a95c-a01e8e96e510",
"description": "EOW on Thursday translates to Sunday at eight in the evening",
"property": "deliveryDate",
"input": {
"meetingStart": "2011-05-19T00:00:00",
"description": "EOW"
},
"expected": "2011-05-22T20:00:00"
},
{
"uuid": "bbffccf7-97f7-4244-888d-bdd64348fa2e",
"description": "EOW on Friday translates to Sunday at eight in the evening",
"property": "deliveryDate",
"input": {
"meetingStart": "2022-08-05T00:00:00",
"description": "EOW"
},
"expected": "2022-08-07T20:00:00"
},
{
"uuid": "439bf09f-3a0e-44e7-bad5-b7b6d0c4505a",
"description": "2M translates to the first workday of the second month",
"property": "deliveryDate",
"input": {
"meetingStart": "2007-01-02T00:00:00",
"description": "2M"
},
"expected": "2007-02-01T08:00:00"
},
{
"uuid": "86d82e83-c481-4fb4-9264-625de7521340",
"description": "5M translates to the first workday of the fifth month",
"property": "deliveryDate",
"input": {
"meetingStart": "2013-02-11T00:00:00",
"description": "5M"
},
"expected": "2013-05-01T08:00:00"
},
{
"uuid": "06d401e3-8461-438f-afae-8d26aa0289e0",
"description": "Q1 translates to the last workday of the first quarter",
"property": "deliveryDate",
"input": {
"meetingStart": "2011-02-23T00:00:00",
"description": "Q1"
},
"expected": "2011-03-31T08:00:00"
},
{
"uuid": "eebd5f32-b16d-4ecd-91a0-584b0364b7ed",
"description": "Q4 translates to the last workday of the fourth quarter",
"property": "deliveryDate",
"input": {
"meetingStart": "2023-04-19T00:00:00",
"description": "Q4"
},
"expected": "2023-12-29T08:00:00"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a test case that wraps around to the next year?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea. I think it makes the most sense to have that as part of the ASAP tests. I'll add it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second hand, the quarters suggestion is good! I've updated the description, I'll add the test cases later. Could you check if the description makes sense?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added test cases too

}
]
}
40 changes: 40 additions & 0 deletions exercises/swift-scheduling/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Instructions

Your task is to convert delivery date descriptions to _actual_ delivery dates, based on when the meeting started.

There are two types of delivery date descriptions:

1. Fixed: a predefined set of words.
2. Variable: words that have a variable component, but follow a predefined set of patterns.

## Fixed delivery date descriptions

There are three fixed delivery date descriptions:

- `"NOW"`
- `"ASAP"` (As Soon As Possible)
- `"EOW"` (End Of Week)

The following table lists how to translate them:

| Description | Meeting start | Delivery date |
| ----------- | ---------------------------- | ----------------------------------- |
| `"NOW"` | - | Two hours after the meeting started |
| `"ASAP"` | Before 12:00 | Today at 17:00 |
| `"ASAP"` | After 12:00 | Tomorrow at 12:00 |
| `"EOW"` | Monday, Tuesday or Wednesday | Friday at 5:00 |
| `"EOW"` | Thursday or Friday | Sunday at 20:00 |

## Variable delivery date descriptions

There are two variable delivery date description patterns:

- `"<N>M"` (N-th month)
- `"Q<N>"` (N-th quarter)

| Description | Delivery date |
| ----------- | ---------------------------------------------------------------------- |
| `"<N>M"` | At 8:00 on the _first_ work day<sup>1</sup> of this year's N-th month |

Check failure on line 37 in exercises/swift-scheduling/instructions.md

View workflow job for this annotation

GitHub Actions / Lint markdown files

Inline HTML

exercises/swift-scheduling/instructions.md:37:48 MD033/no-inline-html Inline HTML [Element: sup] https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md033.md
| `"Q<N>"` | At 8:00 on the _last_ work day<sup>1</sup> of this year's N-th quarter |

Check failure on line 38 in exercises/swift-scheduling/instructions.md

View workflow job for this annotation

GitHub Actions / Lint markdown files

Inline HTML

exercises/swift-scheduling/instructions.md:38:47 MD033/no-inline-html Inline HTML [Element: sup] https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md033.md

<sup>1</sup> A work day is either a Monday, Tuesday, Wednesday, Thursday or Friday.

Check failure on line 40 in exercises/swift-scheduling/instructions.md

View workflow job for this annotation

GitHub Actions / Lint markdown files

Inline HTML

exercises/swift-scheduling/instructions.md:40:1 MD033/no-inline-html Inline HTML [Element: sup] https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md033.md
6 changes: 6 additions & 0 deletions exercises/swift-scheduling/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Introduction

This week, it is your turn to take notes in the department's planning meeting.
In this meeting, your boss will set delivery dates for all open work items.
Annoyingly, instead of specifying the _actual_ delivery date, your boss will only _describe them_ in an annoying abbreviated format.
As many of your colleagues won't be familiar with this corporate lingo, you'll need to convert these delivery date descriptions to actual delivery dates.
2 changes: 2 additions & 0 deletions exercises/swift-scheduling/metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title = "Swift Scheduling"
blurb = "Convert delivery date descriptions to actual delivery dates."
Loading