https://github.com/pjsalter/java-timetraveler-toolkit
โฐ Java TimeTraveler Toolkit ๐ provides essential date and time calculation functions to effortlessly navigate the temporal landscape using Java's Date/Time API.
https://github.com/pjsalter/java-timetraveler-toolkit
java java20 junit5 jupiter maven
Last synced: 3 months ago
JSON representation
โฐ Java TimeTraveler Toolkit ๐ provides essential date and time calculation functions to effortlessly navigate the temporal landscape using Java's Date/Time API.
- Host: GitHub
- URL: https://github.com/pjsalter/java-timetraveler-toolkit
- Owner: PJSalter
- Created: 2023-10-20T15:34:56.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-20T17:04:22.000Z (about 2 years ago)
- Last Synced: 2025-01-03T11:22:08.437Z (about 1 year ago)
- Topics: java, java20, junit5, jupiter, maven
- Language: Java
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# โฐ Java TimeTraveler Toolkit ๐
This Java project provides a set of functions for performing various date and time calculations using the Java Date/Time API. These functions include:
- `getTodaysDate()`: Returns today's date.
- `getLaterDatebyDays(LocalDate date, int x)`: Returns the date corresponding to x days after the input date.
- `getPreviousDatebyWeeks(LocalDate date, int x)`: Returns the date corresponding to x weeks before the input date.
- `getTimeDifference(LocalDate date1, LocalDate date2)`: Returns the time difference between two input dates in years, months, and days in the format "Year-20:Months-5:Days-1".
## Usage
You can use these date and time functions in your Java projects as follows:
```java
package com.company;
import java.time.LocalDate;
public class JavaTimeTravelerToolkit {
public static void main(String[] args) {
// Print today's date
System.out.println("Today's date is: " + getTodaysDate());
// Print the date 14 days from today
System.out.println("14 days from today is: " + getLaterDatebyDays(getTodaysDate(), 14));
// Print the date 5 weeks before today
System.out.println("5 weeks prior to today was: " + getPreviousDatebyWeeks(getTodaysDate(), 5));
// Calculate and print the time difference between today and June 30, 2031
System.out.println("The difference between today and June 30, 2031 is: " +
getTimeDifference(getTodaysDate(), LocalDate.of(2031, 06, 30)));
}
}
```
## ๐งช Testing
This project includes JUnit 5 tests to ensure the correctness of the date and time functions. You can run the tests using your preferred IDE or build tool.
```java
// One of my Tests to check if function returns today's date.
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@DisplayName("Java Time Traveler Toolkit functionality for Date and Time")
class JavaTimeTravelerToolkitTest {
@org.junit.jupiter.api.Test
@DisplayName("Positive Test case - Check whether function returns today's date successfully")
public void getTodaysDate() {
LocalDate expected = LocalDate.now();
LocalDate actual = JavaTimeTravelerToolkit.getTodaysDate();
Assertions.assertEquals(expected, actual);
}
}
```
## Authored by: [Peter James Salter](https://github.com/PJSalter)
## โจHappy Coding ๐