From fb1ce3a05902d866c5d416a1f7a871b25ebeae62 Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Mon, 2 Dec 2024 14:51:32 +0100 Subject: [PATCH 1/3] Update README.md --- README.md | 57 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5b4a62e..1ce9646 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ [![Go](https://github.com/manuelarte/GoTime/actions/workflows/go.yml/badge.svg)](https://github.com/manuelarte/GoTime/actions/workflows/go.yml) ![coverage](https://raw.githubusercontent.com/manuelarte/GoTime/badges/.badges/main/coverage.svg) -# 🕐 GoTime 🕐 +# 🕐 GoTime + +GoTime is a Go library for working with time periods, enabling easy creation and overlap calculation. GoTime simplifies the creation and manipulation of time periods, allowing you to easily define, compare, and compute overlaps between time intervals. ## 📝 How to install it @@ -12,28 +14,61 @@ GoTime contains the following utility struct ### TimePeriod -Construct a time period based on start time and end time. +Create a `TimePeriod` instance by specifying a start time and an end time: > tp, err := NewTimePeriod(startTime, endTime) ++ `startTime`: The beginning of the time period. Use time.Time{} for no lower limit. ++ `endTime`: The end of the time period. Use time.Time{} for no upper limit. +Returns: ++ `tp`: The resulting TimePeriod. ++ `err`: An error if the inputs are invalid. + The time period is built based on the overlapping period between the two dates. ``` -t1 ____|________ -t2 _________| -tp ____|‾‾‾‾|___ +Input Times +time1 ____|________... +time2 _________|___... +Resulting Time Period +tp ____|‾‾‾‾|___... ``` -If start time or end time are zero, it means no limit. +Passing a zero value for `startTime` or `endTime` indicates an unbounded period on that side. + +--- -The struct also provides a function `Overlaps` to check whether two time periods overlaps, and what is the overlapping period +The struct also provides a function `Overlaps`. This method checks whether two time periods overlap and, if so, returns the overlapping period. e.g. ``` -tp1 ____|‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -tp2 _________|‾‾‾‾‾‾|__ -tp ____|‾‾‾‾|_________ +Input Time Periods +tp1 ____|‾‾‾‾‾‾‾‾‾‾‾‾‾‾... +tp2 _________|‾‾‾‾‾‾|__... +Resulting Overlap +tp ____|‾‾‾‾|_________... +``` + +## Full Example + ``` +start1 := time.Date(2024, 12, 1, 0, 0, 0, 0, time.UTC) +end1 := time.Date(2024, 12, 10, 0, 0, 0, 0, time.UTC) +tp1, _ := NewTimePeriod(start1, end1) + +start2 := time.Date(2024, 12, 5, 0, 0, 0, 0, time.UTC) +end2 := time.Date(2024, 12, 15, 0, 0, 0, 0, time.UTC) +tp2, _ := NewTimePeriod(start2, end2) + +overlapExists, overlapPeriod := tp1.Overlaps(tp2) +fmt.Println("Overlap Exists:", overlapExists) +fmt.Println("Overlap Period:", overlapPeriod) +``` + +## 📂 Examples + +Refer to the [examples](./examples) directory for usage examples. -For more information check the [examples](./examples) +## 📜 License +This project is licensed under the MIT License. From daa79f9b1b42e8487588dd084735481ca20a51ac Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Mon, 2 Dec 2024 14:52:05 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1ce9646..41c13c2 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Create a `TimePeriod` instance by specifying a start time and an end time: > tp, err := NewTimePeriod(startTime, endTime) -+ `startTime`: The beginning of the time period. Use time.Time{} for no lower limit. -+ `endTime`: The end of the time period. Use time.Time{} for no upper limit. ++ `startTime`: The beginning of the time period. Use `time.Time{}` for no lower limit. ++ `endTime`: The end of the time period. Use `time.Time{}` for no upper limit. Returns: + `tp`: The resulting TimePeriod. + `err`: An error if the inputs are invalid. From 37832ac5075a9259b17687a41852d6f444194e71 Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Mon, 2 Dec 2024 14:52:25 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 41c13c2..2189837 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ tp ____|‾‾‾‾|_________... ## Full Example -``` +```go start1 := time.Date(2024, 12, 1, 0, 0, 0, 0, time.UTC) end1 := time.Date(2024, 12, 10, 0, 0, 0, 0, time.UTC) tp1, _ := NewTimePeriod(start1, end1)