Merged in chore/SW-3145-move-date-to-design-system (pull request #2556)
feat: SW-3145 Moved date component to design system * chore: SW-3145 Moved date component to design system Approved-by: Anton Gunnarsson Approved-by: Matilda Landström
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
"./utils/chunk": "./utils/chunk.ts",
|
||||
"./utils/isDefined": "./utils/isDefined.ts",
|
||||
"./utils/maskValue": "./utils/maskValue.ts",
|
||||
"./utils/dateFormatting": "./utils/dateFormatting.ts",
|
||||
"./utils/rangeArray": "./utils/rangeArray.ts",
|
||||
"./utils/zod/*": "./utils/zod/*.ts",
|
||||
"./constants/language": "./constants/language.ts",
|
||||
"./constants/membershipLevels": "./constants/membershipLevels.ts",
|
||||
|
||||
21
packages/common/utils/dateFormatting.ts
Normal file
21
packages/common/utils/dateFormatting.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { dt } from "../dt/dt"
|
||||
|
||||
import type { Lang } from "../constants/language"
|
||||
|
||||
/**
|
||||
* Get the localized month name for a given month index and language
|
||||
* @param monthIndex - The month index (1-12)
|
||||
* @param lang - the language to use, Lang enum
|
||||
* @returns The localized month name
|
||||
*/
|
||||
export function getLocalizedMonthName(monthIndex: number, lang: Lang) {
|
||||
const monthName = new Date(2024, monthIndex - 1).toLocaleString(lang, {
|
||||
month: "long",
|
||||
})
|
||||
|
||||
return monthName.charAt(0).toUpperCase() + monthName.slice(1)
|
||||
}
|
||||
|
||||
export function getNumberOfNights(startDate: string, endDate: string) {
|
||||
return dt(endDate).diff(startDate, "day")
|
||||
}
|
||||
6
packages/common/utils/rangeArray.ts
Normal file
6
packages/common/utils/rangeArray.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export function rangeArray(start: number, stop: number, step: number = 1) {
|
||||
return Array.from(
|
||||
{ length: (stop - start) / step + 1 },
|
||||
(_, index) => start + index * step
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user