Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

57 wiersze
2.1 KiB

  1. import { SessionWithTokens, authOptions } from "@/config/authConfig"
  2. import { getServerSession } from "next-auth"
  3. export interface WildCard {
  4. [key: string]: any;
  5. }
  6. export const dateInRange = (currentDate: string, startDate: string, endDate: string) => {
  7. if (currentDate === undefined) {
  8. return false // can be changed to true if necessary
  9. }
  10. const currentDateTime = new Date(currentDate).getTime()
  11. const startDateTime = startDate === undefined || startDate.length === 0 ? undefined : new Date(startDate).getTime()
  12. const endDateTime = endDate === undefined || startDate.length === 0 ? undefined : new Date(endDate).getTime()
  13. // console.log(currentDateTime, startDateTime, endDateTime)
  14. if (startDateTime === undefined && endDateTime !== undefined) {
  15. return currentDateTime <= endDateTime
  16. } else if (startDateTime !== undefined && endDateTime === undefined) {
  17. return currentDateTime >= startDateTime
  18. } else {
  19. if (startDateTime !== undefined && endDateTime !== undefined) {
  20. return currentDateTime >= startDateTime && currentDateTime <= endDateTime
  21. } else {
  22. return true
  23. }
  24. }
  25. }
  26. export const downloadFile = (blobData: Uint8Array, filename: string) => {
  27. const url = URL.createObjectURL(new Blob([blobData]));
  28. const link = document.createElement("a");
  29. link.href = url;
  30. link.setAttribute("download", filename);
  31. link.click();
  32. }
  33. export function readIntFromString(input: string): [string, number | null] | string {
  34. // Split the input string by the "-" character
  35. if (!input.includes("-")) {
  36. return [input, null]
  37. }
  38. const parts = input.split("-");
  39. // Extract the string part and the integer part (if available)
  40. const stringPart = parts.slice(0, parts.length - 1).join("-");
  41. const intPartStr = parts[parts.length - 1];
  42. const intPart = intPartStr ? parseInt(intPartStr, 10) : null;
  43. return [stringPart, intPart];
  44. }
  45. export const getUserAbilities = async () => {
  46. const session = await getServerSession(authOptions) as SessionWithTokens;
  47. return session?.abilities ?? []
  48. }