-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api): share dayjs lib to utilities package
- Loading branch information
Quốc Khánh
committed
Jul 18, 2024
1 parent
178e5bb
commit a1e3110
Showing
10 changed files
with
96 additions
and
52 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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# @6pm/utilities |
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,7 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.8.0/schema.json", | ||
"extends": ["../../biome.json"], | ||
"files": { | ||
"include": ["**/*.ts", "**/*.tsx"] | ||
} | ||
} |
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,17 @@ | ||
{ | ||
"name": "@6pm/utilities", | ||
"version": "1.0.0", | ||
"description": "Shared utilities between apps", | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"check": "biome check" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@6pm/validation": "workspace:^", | ||
"@prisma/client": "^5.16.0", | ||
"dayjs": "^1.11.11" | ||
} | ||
} |
File renamed without changes.
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,47 @@ | ||
import { BudgetPeriodType } from '@prisma/client' | ||
import { dayjsExtended } from './dayjs' | ||
|
||
/** | ||
* Given an anchor date and period type, | ||
* calculate the start and end dates of the budget period. | ||
* Example: | ||
* - anchorDate: 2022-01-15 | ||
* - periodType: MONTHLY | ||
* - startDate: 2022-01-01 | ||
* - endDate: 2022-01-31 | ||
*/ | ||
export function calculateBudgetPeriodStartEndDates({ | ||
anchorDate, | ||
type, | ||
}: { | ||
anchorDate: Date | ||
type: BudgetPeriodType | ||
}) { | ||
switch (type) { | ||
case BudgetPeriodType.WEEKLY: | ||
return { | ||
startDate: dayjsExtended(anchorDate).startOf('week').toDate(), | ||
endDate: dayjsExtended(anchorDate).endOf('week').toDate(), | ||
} | ||
case BudgetPeriodType.MONTHLY: | ||
return { | ||
startDate: dayjsExtended(anchorDate).startOf('month').toDate(), | ||
endDate: dayjsExtended(anchorDate).endOf('month').toDate(), | ||
} | ||
case BudgetPeriodType.QUARTERLY: | ||
return { | ||
startDate: dayjsExtended(anchorDate).startOf('quarter').toDate(), | ||
endDate: dayjsExtended(anchorDate).endOf('quarter').toDate(), | ||
} | ||
case BudgetPeriodType.YEARLY: | ||
return { | ||
startDate: dayjsExtended(anchorDate).startOf('year').toDate(), | ||
endDate: dayjsExtended(anchorDate).endOf('year').toDate(), | ||
} | ||
default: | ||
return { | ||
startDate: null, | ||
endDate: null, | ||
} | ||
} | ||
} |
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,2 @@ | ||
export * from './date/dayjs' | ||
export * from './date/period' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.