feat: Test running overhaul, switch to Prettier & reformat everything (#1407)

* chore: Switch to Node 20 + Vitest

* chore: migrate to vitest mock functions

* chore: code style (switch to prettier)

* test: re-enable long-running test

Seems the switch to Node 20 and Vitest has vastly improved the code's and / or the test's runtime!

see #1193

* chore: code style

* chore: fix failing tests

* Updated Documentation in README.md

* Update contribution guidelines to state usage of Prettier

* fix: set prettier printWidth back to 80

* chore: apply updated code style automatically

* fix: set prettier line endings to lf again

* chore: apply updated code style automatically

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
Roland Hummel
2023-10-03 23:08:19 +02:00
committed by GitHub
parent 0ca18c2b2c
commit 86d333ee94
392 changed files with 5849 additions and 16622 deletions

View File

@ -1,12 +1,12 @@
/*
* This algorithm accepts a month in the format mm/yyyy.
* And prints out the month's calendar.
* It uses an epoch of 1/1/1900, Monday.
*/
* This algorithm accepts a month in the format mm/yyyy.
* And prints out the month's calendar.
* It uses an epoch of 1/1/1900, Monday.
*/
import { isLeapYear } from '../Maths/LeapYear'
class Month {
constructor () {
constructor() {
this.Days = ['M', 'T', 'W', 'Th', 'F', 'S', 'Su']
this.BDays = ['M', 'Su', 'S', 'F', 'Th', 'W', 'T']
this.epoch = { month: 1, year: 1900 }
@ -14,9 +14,10 @@ class Month {
this.monthDaysLeap = [31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
}
printCal (days, startDay, output = value => console.log(value)) {
printCal(days, startDay, output = (value) => console.log(value)) {
output('M T W Th F S Su')
const dates = []; let i
const dates = []
let i
for (i = 1; i <= days; i++) {
dates.push(i)
}
@ -25,9 +26,9 @@ class Month {
}
while (true) {
let row = ''
for (i = 0; (i < 7) && (dates.length !== 0); i++) {
for (i = 0; i < 7 && dates.length !== 0; i++) {
row += dates.shift()
while ((row.length % 4) !== 0) {
while (row.length % 4 !== 0) {
row += ' '
}
}
@ -36,8 +37,10 @@ class Month {
}
}
parseDate (date) {
const dateAr = []; let block = ''; let i
parseDate(date) {
const dateAr = []
let block = ''
let i
for (i = 0; i < date.length; i++) {
if (date[i] === '/') {
dateAr.push(parseInt(block))
@ -52,7 +55,7 @@ class Month {
return dateOb
}
isGreater (startDate, endDate) {
isGreater(startDate, endDate) {
if (startDate.year > endDate.year) {
return true
} else if (startDate.year < endDate.year) {
@ -65,26 +68,28 @@ class Month {
return true
}
getDayDiff (startDate, endDate) {
getDayDiff(startDate, endDate) {
if (this.isGreater(startDate, endDate) === null) {
return 0
} else if ((this.isGreater(startDate, endDate) === true)) {
} else if (this.isGreater(startDate, endDate) === true) {
const midDate = startDate
startDate = endDate
endDate = midDate
}
let diff = 0
while (startDate.year !== endDate.year) {
diff += (isLeapYear(startDate.year)) ? 366 : 365
diff += isLeapYear(startDate.year) ? 366 : 365
startDate.year = startDate.year + 1
}
while (startDate.month !== endDate.month) {
if (startDate.month < endDate.month) {
if (isLeapYear(startDate.year)) diff += this.monthDaysLeap[startDate.month]
if (isLeapYear(startDate.year))
diff += this.monthDaysLeap[startDate.month]
else diff += this.monthDays[startDate.month]
startDate.month = startDate.month + 1
} else {
if (isLeapYear(startDate.year)) diff -= this.monthDaysLeap[startDate.month - 1]
if (isLeapYear(startDate.year))
diff -= this.monthDaysLeap[startDate.month - 1]
else diff -= this.monthDays[startDate.month - 1]
startDate.month = startDate.month - 1
}
@ -92,14 +97,18 @@ class Month {
return diff
}
generateMonthCal (date) {
const Month = this.parseDate(date); let day = ''
generateMonthCal(date) {
const Month = this.parseDate(date)
let day = ''
let difference = this.getDayDiff(this.epoch, Month)
difference = difference % 7
let Month2 = this.parseDate(date)
day = (this.isGreater(Month2, this.epoch)) ? this.Days[difference] : this.BDays[difference]
day = this.isGreater(Month2, this.epoch)
? this.Days[difference]
: this.BDays[difference]
Month2 = this.parseDate(date)
if (isLeapYear(Month2.year)) this.printCal(this.monthDaysLeap[Month2.month], day)
if (isLeapYear(Month2.year))
this.printCal(this.monthDaysLeap[Month2.month], day)
else this.printCal(this.monthDays[Month2.month], day)
}
}