-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): ♻️ clean the code to be more reddeable and scalable -…
… update deps to latest version
- Loading branch information
Showing
20 changed files
with
1,571 additions
and
616 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: 🚀 pkg-pr-new | ||
on: | ||
push: | ||
pull_request: | ||
branches-ignore: main | ||
paths-ignore: | ||
- "website/*" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9 | ||
|
||
- name: Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
|
||
- name: Build | ||
run: pnpm run build | ||
|
||
- run: npx pkg-pr-new publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './types'; | ||
export * from './constants'; | ||
export * from './utils/date-generator'; | ||
export * from './utils/get-week-number'; | ||
export * from './utils/date'; | ||
export * from './utils/keyboard'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import type { LocalDate, Month } from '../types'; | ||
|
||
type DaysArrParams = { | ||
month: Month; | ||
year: string; | ||
fullWeeks?: boolean; | ||
}; | ||
|
||
const formatDate = (y: number, m: number, d: number) => { | ||
const mm = m < 10 ? `0${m}` : m; | ||
const dd = d < 10 ? `0${d}` : d; | ||
return `${y}-${mm}-${dd}`; | ||
}; | ||
|
||
const getCalendarStartDate = (year: number, month: number) => { | ||
const firstDayOfMonth = new Date(year, month - 1, 1); | ||
const firstDayOfWeek = firstDayOfMonth.getDay(); | ||
const startDate = new Date(firstDayOfMonth); | ||
startDate.setDate(1 - firstDayOfWeek); | ||
return startDate; | ||
}; | ||
|
||
const generateFullWeeks = (year: number, month: number) => { | ||
const startDate = getCalendarStartDate(year, month); | ||
const days: string[] = []; | ||
|
||
for (let i = 0; i < 42; i++) { | ||
const currentDate = new Date(startDate); | ||
currentDate.setDate(startDate.getDate() + i); | ||
days.push(formatDate(currentDate.getFullYear(), currentDate.getMonth() + 1, currentDate.getDate())); | ||
} | ||
|
||
return Array.from({ length: 6 }, (_, i) => days.slice(i * 7, (i + 1) * 7)); | ||
}; | ||
|
||
const generatePartialWeeks = (year: number, month: number) => { | ||
const firstDayOfMonth = new Date(year, month - 1, 1); | ||
// Fix: Handle Sunday (0) by converting it to 7, otherwise use the day number | ||
const firstDayOfWeek = firstDayOfMonth.getDay(); | ||
console.log({ firstDayOfWeek, firstDayOfMonth }); | ||
const daysInMonth = new Date(year, month, 0).getDate(); | ||
|
||
const previousDays = Array(firstDayOfWeek).fill(null); | ||
const currentDays = Array.from({ length: daysInMonth }, (_, i) => formatDate(year, month, i + 1)); | ||
const totalDays = previousDays.length + currentDays.length; | ||
const trailingNulls = Array((7 - (totalDays % 7)) % 7).fill(null); | ||
|
||
const allDays = [...previousDays, ...currentDays, ...trailingNulls]; | ||
return Array.from({ length: allDays.length / 7 }, (_, i) => allDays.slice(i * 7, (i + 1) * 7)); | ||
}; | ||
|
||
export const generateCalendarDays = ({ month, year, fullWeeks = false }: DaysArrParams) => { | ||
const numericYear = Number.parseInt(year, 10); | ||
const numericMonth = Number.parseInt(month, 10); | ||
|
||
return fullWeeks ? generateFullWeeks(numericYear, numericMonth) : generatePartialWeeks(numericYear, numericMonth); | ||
}; | ||
|
||
/** | ||
* Calculates ISO week number for a date | ||
* @param date - Date in LocalDate format | ||
* @returns ISO week number | ||
*/ | ||
export const getISOWeekNumber = (date: LocalDate): number => { | ||
const d = new Date(date); | ||
d.setHours(0, 0, 0, 0); | ||
d.setDate(d.getDate() + 4 - (d.getDay() || 7)); | ||
const yearStart = new Date(d.getFullYear(), 0, 1); | ||
return Math.ceil(((d.getTime() - yearStart.getTime()) / 86400000 + 1) / 7); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.