Files
tech-tracker-next/src/lib/utils.ts

37 lines
840 B
TypeScript

import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export const makeConditionalClassName = ({
context,
defaultClassName,
on = '',
off = '',
}: {
context: boolean;
defaultClassName: string;
on?: string;
off?: string;
}) => {
return defaultClassName + ' ' + (context ? on : off);
};
export const formatTime = (timestamp: string) => {
const date = new Date(timestamp);
const time = date.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: 'numeric',
});
return time;
};
export const formatDate = (timestamp: string) => {
const date = new Date(timestamp);
const day = date.getDate();
const month = date.toLocaleString('default', { month: 'long' });
return `${month} ${day}`;
};