mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-21 06:34:30 +01:00
Added jotai (#14)
* Added jotai * cache settings by using jotai state * use hydrateAtom with SSR * remove useSettings * fix test
This commit is contained in:
4
lib/atoms.ts
Normal file
4
lib/atoms.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { atom } from "jotai";
|
||||
import { getDefaultSettings } from "./types";
|
||||
|
||||
export const settingsAtom = atom(getDefaultSettings())
|
||||
@@ -9,7 +9,7 @@ export function cn(...inputs: ClassValue[]) {
|
||||
// get today's date string for timezone
|
||||
export function getTodayInTimezone(timezone: string): string {
|
||||
const now = getNow({ timezone });
|
||||
return d2s({ dateTime: now, format: 'yyyy-MM-dd' });
|
||||
return d2s({ dateTime: now, format: 'yyyy-MM-dd', timezone });
|
||||
}
|
||||
|
||||
// get datetime object of now
|
||||
@@ -34,11 +34,11 @@ export function d2t({ dateTime, timezone = 'utc' }: { dateTime: DateTime, timezo
|
||||
}
|
||||
|
||||
// convert datetime object to string, mostly for display
|
||||
export function d2s({ dateTime, format }: { dateTime: DateTime, format?: string }) {
|
||||
export function d2s({ dateTime, format, timezone }: { dateTime: DateTime, format?: string, timezone: string }) {
|
||||
if (format) {
|
||||
return dateTime.toFormat(format);
|
||||
return dateTime.setZone(timezone).toFormat(format);
|
||||
}
|
||||
return dateTime.toLocaleString(DateTime.DATETIME_MED);
|
||||
return dateTime.setZone(timezone).toLocaleString(DateTime.DATETIME_MED);
|
||||
}
|
||||
|
||||
// convert datetime object to date string, mostly for display
|
||||
|
||||
Reference in New Issue
Block a user