Skip to content

Commit

Permalink
Fixed: can perform ShiftRange.get()
Browse files Browse the repository at this point in the history
  • Loading branch information
DurianDan committed Dec 11, 2024
1 parent 4f29855 commit 6196089
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyshiftsla"
version = "0.3.0"
version = "0.4.0"
description = "Highly customizable SLA and work-shifts Generator, for any time-keeping and days-off policies"
authors = ["Huy Vu Nguyen <[email protected]>"]
readme = "README.md"
Expand Down
12 changes: 6 additions & 6 deletions pyshiftsla/shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ def get_overlap(self, other: "Shift") -> RESOLVED_OVERLAPPED_SHIFT:
def get_outer(
self,
other: "Shift",
resovled_overlap: RESOLVED_OVERLAPPED_SHIFT | None = None,
resolved_overlap: RESOLVED_OVERLAPPED_SHIFT | None = None,
) -> RESOLVED_OUTER_SHIFTS:
"""Get the outer `Shift`s of 2 overlapped `Shift`s,
return both of them, if not overlapped
"""
if resovled_overlap is None:
resovled_overlap = self.get_overlap(other)
if resolved_overlap is None:
resolved_overlap = self.get_overlap(other)
outer_shifts = [self]
match resovled_overlap["compare_result"]:
match resolved_overlap["compare_result"]:
case "smaller" | "greater":
outer_shifts.append(other)
case "end-connects-start" | "start-connects-end":
Expand All @@ -209,10 +209,10 @@ def get_outer(
outer_shifts = [
Shift(
start=min([self.start, other.start]),
end=resovled_overlap["overlapped"].start,
end=resolved_overlap["overlapped"].start,
),
Shift(
start=resovled_overlap["overlapped"].end,
start=resolved_overlap["overlapped"].end,
end=max([self.end, other.end]),
),
]
Expand Down
9 changes: 8 additions & 1 deletion pyshiftsla/shiftrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
class ShiftRange(RootModel):
root: Dict[date, DailyShift]

def __getitem__(self, key: date) -> DailyShift | None:
def __getitem__(self, key: date) -> DailyShift:
if not isinstance(key, date):
raise NotImplementedError(
f"Only accept key as `date` not {type(key)}"
)
return self.root[key]

def get(self, key: date) -> DailyShift | None:
if not isinstance(key, date):
raise NotImplementedError(
f"Only accept key as `date` not {type(key)}"
)
return self.root.get(key)

@property
def _start_date(self) -> date:
return max(self.root)
Expand Down
1 change: 1 addition & 0 deletions tests/test_readme_showcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def test_readme_first_showcase_us_woman():
with pytest.raises(KeyError):
# KeyError: datetime.date(2024, 7, 4)
generated_shiftrange[date(2024, 7, 4)]
assert generated_shiftrange.get(date(2024, 7, 4)) is None


def test_readme_second_showcase_us_woman_sla():
Expand Down

0 comments on commit 6196089

Please sign in to comment.