Skip to content
Merged
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
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,14 @@
"prerequisites": [],
"difficulty": 5
},
{
"slug": "swift-scheduling",
"name": "Swift Scheduling",
"uuid": "1708d1f2-f588-43f0-a247-8072efcff288",
"practices": [],
"prerequisites": [],
"difficulty": 6
},
{
"slug": "variable-length-quantity",
"name": "Variable Length Quantity",
Expand Down
50 changes: 50 additions & 0 deletions exercises/practice/swift-scheduling/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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 shows how to translate them:

| Description | Meeting start | Delivery date |
| ----------- | ----------------------------- | ----------------------------------- |
| `"NOW"` | - | Two hours after the meeting started |
| `"ASAP"` | Before 13:00 | Today at 17:00 |
| `"ASAP"` | After or at 13:00 | Tomorrow at 13:00 |
| `"EOW"` | Monday, Tuesday, or Wednesday | Friday at 17: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 | Meeting start | Delivery date |
| ----------- | ------------------------- | --------------------------------------------------------- |
| `"<N>M"` | Before N-th month | At 8:00 on the _first_ workday of this year's N-th month |
| `"<N>M"` | After or in N-th month | At 8:00 on the _first_ workday of next year's N-th month |
| `"Q<N>"` | Before or in N-th quarter | At 8:00 on the _last_ workday of this year's N-th quarter |
| `"Q<N>"` | After N-th quarter | At 8:00 on the _last_ workday of next year's N-th quarter |

~~~~exercism/note
A workday is a Monday, Tuesday, Wednesday, Thursday, or Friday.

A year has four quarters, each with three months:
1. January/February/March
2. April/May/June
3. July/August/September
4. October/November/December.
~~~~
6 changes: 6 additions & 0 deletions exercises/practice/swift-scheduling/.docs/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 dates, your boss will only _describe them_ in an 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.
22 changes: 22 additions & 0 deletions exercises/practice/swift-scheduling/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"authors": [
"IsaacG"
],
"files": {
"solution": [
"swift_scheduling.gd"
],
"test": [
"swift_scheduling_test.gd",
"run_tests",
"lib/test_runner.gd",
"project.godot"
],
"example": [
".meta/example.gd"
]
},
"blurb": "Convert delivery date descriptions to actual delivery dates.",
"source": "Erik Schierboom",
"source_url": "https://github.com/exercism/problem-specifications/pull/2536"
}
68 changes: 68 additions & 0 deletions exercises/practice/swift-scheduling/.meta/example.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const QUARTERS = [[0, 4], [0, 7], [0, 10], [1, 1]]

func delivery_date(start: String, description: String):
var now_details = Time.get_datetime_dict_from_datetime_string(start, true)
var now_ts = Time.get_unix_time_from_datetime_string(start)
var delivery = null
var offset = 0
if description == "NOW":
# NOW: Two hours after the meeting started
offset = 2 * 60 * 60
elif description == "ASAP":
# ASAP Before 12:00 => Today at 17:00
# ASAP After 12:00 => Tomorrow at 12:00
if now_details["hour"] <= 12:
now_details["hour"] = 17
else:
now_details["hour"] = 13
offset = 24 * 60 * 60
now_details["minute"] = 0
now_details["second"] = 0
elif description == "EOW":
# EOW Monday, Tuesday, Wednesday => Friday at 17:00
# EOW Thursday or Friday => Sunday at 20:00
if now_details["weekday"] in [Time.WEEKDAY_MONDAY, Time.WEEKDAY_TUESDAY, Time.WEEKDAY_WEDNESDAY]:
now_details["hour"] = 17
offset = 24 * 60 * 60 * (Time.WEEKDAY_FRIDAY - now_details["weekday"])
else:
now_details["hour"] = 20
offset = 24 * 60 * 60 * (Time.WEEKDAY_SATURDAY + 1 - now_details["weekday"])
now_details["minute"] = 0
now_details["second"] = 0
elif description.ends_with("M"):
# "<N>M" Before N-th month => At 8:00 on the first workday¹ of this year's N-th month
# "<N>M" After or in N-th month => At 8:00 on the first workday¹ of next year's N-th month
var target_month = int(description.rstrip("M"))
if now_details["month"] >= target_month:
now_details["year"] += 1
now_details["month"] = target_month
now_details["day"] = 1
now_details["hour"] = 8
now_details["minute"] = 0
now_details["second"] = 0

# Ensure it is not a weekend -- compute day of week and roll forward to Monday.
now_details = Time.get_datetime_dict_from_unix_time(Time.get_unix_time_from_datetime_dict(now_details))
if now_details["weekday"] == Time.WEEKDAY_SATURDAY:
offset += 24 * 60 * 60 * 2
elif now_details["weekday"] == Time.WEEKDAY_SUNDAY:
offset += 24 * 60 * 60 * 1
elif description[0] == "Q":
# "Q<N>" Before or in N-th quarter² => At 8:00 on the last workday¹ of this year's N-th quarter²
# "Q<N>" After N-th quarter² => At 8:00 on the last workday¹ of next year's N-th quarter²
var quarter = int(description.lstrip("Q"))
var current = ((now_details["month"] - 1) / 3) + 1
var year_offset = QUARTERS[quarter - 1][0]
var month = QUARTERS[quarter - 1][1]
if current > quarter:
year_offset = 1
now_details = {"year": now_details["year"] + year_offset, "month": month, "day": 1, "hour": 8, "minute": 0, "second": 0}
now_details = Time.get_datetime_dict_from_unix_time(Time.get_unix_time_from_datetime_dict(now_details) - 24 * 60 * 60 * 1)

# Ensure it is not a weekend -- compute day of week and roll backward to Friday.
if now_details["weekday"] == Time.WEEKDAY_SATURDAY:
offset = 24 * 60 * 60 * -1
elif now_details["weekday"] == Time.WEEKDAY_SUNDAY:
offset = 24 * 60 * 60 * -2

return Time.get_datetime_string_from_unix_time(Time.get_unix_time_from_datetime_dict(now_details) + offset)
8 changes: 8 additions & 0 deletions exercises/practice/swift-scheduling/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% for case in cases %}
func test_{{ case.func_name }}(solution_script):
var got = solution_script.{{ case.property | camel_to_snake }}({{ case.input.meetingStart | togdscript }}, {{ case.input.description | togdscript }})
var want = {{ case.expected | togdscript }}
return [got, want]

{% endfor %}

61 changes: 61 additions & 0 deletions exercises/practice/swift-scheduling/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[1d0e6e72-f370-408c-bc64-5dafa9c6da73]
description = "NOW translates to two hours later"

[93325e7b-677d-4d96-b017-2582af879dc2]
description = "ASAP before one in the afternoon translates to today at five in the afternoon"

[cb4252a3-c4c1-41f6-8b8c-e7269733cef8]
description = "ASAP at one in the afternoon translates to tomorrow at one in the afternoon"

[6fddc1ea-2fe9-4c60-81f7-9220d2f45537]
description = "ASAP after one in the afternoon translates to tomorrow at one in the afternoon"

[25f46bf9-6d2a-4e95-8edd-f62dd6bc8a6e]
description = "EOW on Monday translates to Friday at five in the afternoon"

[0b375df5-d198-489e-acee-fd538a768616]
description = "EOW on Tuesday translates to Friday at five in the afternoon"

[4afbb881-0b5c-46be-94e1-992cdc2a8ca4]
description = "EOW on Wednesday translates to Friday at five in the afternoon"

[e1341c2b-5e1b-4702-a95c-a01e8e96e510]
description = "EOW on Thursday translates to Sunday at eight in the evening"

[bbffccf7-97f7-4244-888d-bdd64348fa2e]
description = "EOW on Friday translates to Sunday at eight in the evening"

[d651fcf4-290e-407c-8107-36b9076f39b2]
description = "EOW translates to leap day"

[439bf09f-3a0e-44e7-bad5-b7b6d0c4505a]
description = "2M before the second month of this year translates to the first workday of the second month of this year"

[86d82e83-c481-4fb4-9264-625de7521340]
description = "11M in the eleventh month translates to the first workday of the eleventh month of next year"

[0d0b8f6a-1915-46f5-a630-1ff06af9da08]
description = "4M in the ninth month translates to the first workday of the fourth month of next year"

[06d401e3-8461-438f-afae-8d26aa0289e0]
description = "Q1 in the first quarter translates to the last workday of the first quarter of this year"

[eebd5f32-b16d-4ecd-91a0-584b0364b7ed]
description = "Q4 in the second quarter translates to the last workday of the fourth quarter of this year"

[c920886c-44ad-4d34-a156-dc4176186581]
description = "Q3 in the fourth quarter translates to the last workday of the third quarter of next year"

[7c8f1616-be62-417e-bbd5-a60fa743eccc]
description = "Q2 starting in the last month of the second quarter translates to the last workday of the second quarter of this year"
Loading
Loading