Skip to content

Commit

Permalink
feat: release v1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
r1zyn committed Jul 26, 2022
1 parent 43bc9ee commit 64fe106
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 40 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ This program was written for the 2022 Hackathon.

## Releases

* [`v1.0.4 (Current Release)`](https://github.com/r1zyn/MatarikiProgram/releases/tag/v1.0.4)
* [`v1.0.5 (Current release)`](https://github.com/r1zyn/MatarikiProgram/releases/tag/v1.0.5)
* [`v1.0.4`](https://github.com/r1zyn/MatarikiProgram/releases/tag/v1.0.4)
* [`v1.0.3`](https://github.com/r1zyn/MatarikiProgram/releases/tag/v1.0.3)
* [`v1.0.2`](https://github.com/r1zyn/MatarikiProgram/releases/tag/v1.0.2)
* [`v1.0.1`](https://github.com/r1zyn/MatarikiProgram/releases/tag/v1.0.1)
Expand All @@ -29,7 +30,7 @@ If you prefer to use [`npm`](https://npmjs.com/), be sure to delete [`yarn.lock`
The script for running the program is defined in the `scripts` property in [`package.json`](./package.json)

```cmd
npm run start
npm start
# or
yarn start
```
Expand All @@ -46,26 +47,31 @@ You should see something like this:
## How it works
The program will request you enter a valid year (has to be able to be converted to a number) and will in result output its predictions of when the Matariki holiday for the given year will be.

TypeScript files will be compiled to the `build` directory (only generated once `npm run start` or `yarn start` is executed).
TypeScript files will be compiled to the `build` directory (only generated once `npm start` or `yarn start` is executed).

## Method
To see the original method, view the [`archived`](https://github.com/r1zyn/MatarikiProgram/tree/archived) branch.

The current method is yet to be added.
It is known that the Tangaroa period occurs 22 days after the new moon in May-June. Moreover, the Chinese Lunar calendar is also determined by the moon’s lunar cycle, where the first of the month is the beginning of the new moon. The Chinese lunar month in the Gregorian May-June-July period is May (五月). Therefore, the Tangaroa period begins on the 23rd of May in the Chinese lunar calendar as it is 22 days after the beginning of May. We can convert the lunar date of May 23rd into the Gregorian date, and we can determine the Matariki holiday using this date, by getting the closest Friday.

If the date we use to determine the Matariki holiday is on a weekend, the holiday will be on the previous Friday. Otherwise, the holiday will occur on the next Friday.
Since the Georgian calendar is a solar calendar, we can always predict the Matariki cluster becomes visible at dawn on and after 19 June every year.

## Contributing
See the [contributing guide](.github/CONTRIBUTING.md).

## Todo

* Resolve <https://github.com/r1zyn/MatarikiProgram/issues/5>
* Nothing to do.

## Contributors

* [@r1zyn](https://github.com/r1zyn)
* [@JiachenHH](https://github.com/JiachenHH)
* [@SILentASSassinE](https://github.com/SILentASSassinE)
* [@tommy-duan-macleans](https://github.com/tommy-duan-macleans)
* [@r1zyn](https://github.com/r1zyn) - getMatariki and parseDate functions, commenting
* [@JiachenHH](https://github.com/JiachenHH) - Date utility functions
* [@SILentASSassinE](https://github.com/SILentASSassinE) - Method concept, testing (Jest and manual)
* [@tommy-duan-macleans](https://github.com/tommy-duan-macleans) - index and types files

Note: due to 3 members unfamiliar with `git`, all members contributed via the [`Live Share extension`](https://code.visualstudio.com/learn/collaboration/live-share) for Visual Studio Code, and one member then pushed commits to the repository.

## Import links

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"chalk": "4.1.2",
"jest": "^28.1.3",
"lunar": "^0.0.3",
"lune": "^0.4.0",
"nodemon": "^2.0.19"
},
"devDependencies": {
Expand Down
45 changes: 25 additions & 20 deletions src/utils/closestFriday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,49 @@
* @returns {Date}
*/
export default function closestFriday(fromDate: Date): Date {
if (fromDate.getMonth() === 5 && fromDate.getDate() < 19) {
fromDate.setDate(fromDate.getDate() + 7);
if (fromDate.getMonth() === 5 && fromDate.getDate() <= 19) {
fromDate.setDate(fromDate.getDate() + 7); // If the pointer date is before or on the 19th of June, shift it a week forward (due to June 19th rule)
}

if (fromDate.getDay() === 5) {
return fromDate; // If the day is Friday, keep it as it is
}

/**
* The new Friday date to return.
* @type {Date}
*/
const returnValue: Date = new Date(fromDate);

const difference: number = getDifferenceBetweenDays(5, fromDate.getDay());
returnValue.setDate(returnValue.getDate() + difference);
const difference: number = getDifferenceBetweenDays(5, fromDate.getDay()); // Get the difference between Friday and the day
returnValue.setDate(returnValue.getDate() + difference); // Alter the date accordingly

return returnValue;
return returnValue; // Return the Friday dtae
}

/**
* Function that gets the difference between two days.
* @param {number} start The starting date
* @param {number} end The ending date
* @param {number} weekLength The length of a week
* Function that gets the difference between two days.
* @param {number} start The starting day
* @param {number} end The ending day
* @returns {number}
*/
export function getDifferenceBetweenDays(
start: number,
end: number
// weekLength: number = 7
): number {
/**
* The weekend days for Date.getDay().
* @type {number[]}
*/
const weekends: number[] = [0, 6];
if (weekends.includes(end)) {

if (weekends.includes(end)) { // Checks if the day is a weekend, as if the first day of the Tangaroa period is a weekend, Matariki will be the Friday before, and vice-versa
if (end === 0) {
end = 7;
end = 7; // Change Sunday to index of 7 so we can get the day difference
}

return -(end - start);
return -(end - start); // Get the difference between the day and the previous Friday
} else {
return start - end;
return start - end; // Else, retun the difference between the day and the next Friday
}

// if (end <= 1) {
// return -(weekLength - start + end);
// } else {
// return start - end;
// }
}
14 changes: 8 additions & 6 deletions src/utils/getDateSuffix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
* @returns {string}
*/
export default function getDateSuffix(date: number): string {
if (date > 3 && date < 21) return "th";
switch (date % 10) {
if (date > 3 && date < 21) return "th"; // Return the "th" suffix for corresponding numbers
switch (
date % 10 // Uses modulo division to get the last digit of the date to determine the suffix
) {
case 1:
return "st";
return "st"; // Return the "st" suffix for numbers ending with 1
case 2:
return "nd";
return "nd"; // Return the "nd" suffix for numbers ending with 2
case 3:
return "rd";
return "rd"; // Return the "rd" suffix for numbers ending with 3
default:
return "th";
return "th"; // Return the "th" suffix for numbers ending with 4, 5, 6, 7, 8, 9
}
}
18 changes: 14 additions & 4 deletions src/utils/getMatariki.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import type { MatarikiResult } from "../types";
import closestFriday from "./closestFriday";
// import lune from "lune";
import lunar from "lunar";

/**
* Function that returns the Matariki public holiday for a given year
* and it's pointer date.
* and the first day of the Tangaroa date (or referrenced in the program as "pointer" date)
* @param {string} year The year to find the Matariki public holiday
* @returns
*/
export default function getMatariki(year: string): MatarikiResult {
/**
* The date of the first day of the Tangaroa period.
* @type {Date}
*/
// const pointer: Date = lune.phase_hunt(
// new Date(parseInt(year), 4, 18)
// ).nextnew_date;
// pointer.setDate(pointer.getDate() + 22);

/**
* Pointer date we can use to predict the Matariki public holiday.
* AKA the date of the first day of the Tangaroa period.
* @type {Date}
*/
const pointer: Date = lunar([parseInt(year), 4, 25, true]).toDate();
const pointer: Date = lunar([parseInt(year), 4, 23, true]).toDate();

/**
* Date object representing the Matariki public holiday.
* @type {Date}
*/
const holiday: Date =
pointer.getDay() === 5 ? pointer : closestFriday(pointer);
const holiday: Date = closestFriday(pointer);

return {
holiday,
Expand Down
2 changes: 1 addition & 1 deletion test/getMatariki.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("Get the date for the Matariki public holiday", (): void => {
let mockHoliday: Date;

beforeEach((): void => {
mockPointer = new Date(2022, 5, 22);
mockPointer = new Date(2022, 5, 20);
mockHoliday = new Date(2022, 5, 24);
});

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,11 @@ lunar@^0.0.3:
dependencies:
lodash "^3.7.0"

lune@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/lune/-/lune-0.4.0.tgz#4ac3faaa6cd351236815212e8db7ecd8fb5e2306"
integrity sha512-rMdQf3UWY+fga8vo2MjXkpvqesliljvqIS2AjkEHZLhj7fpgT30S11hoEfug/yNPLy1jWLr2G2esQIzlQjbfpQ==

make-dir@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
Expand Down

0 comments on commit 64fe106

Please sign in to comment.