Skip to content

Commit

Permalink
Upgraded next and prisma. Replaced moment-timezone.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Nov 22, 2024
1 parent 620a838 commit fccb1dd
Show file tree
Hide file tree
Showing 7 changed files with 3,044 additions and 168 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "umami",
"version": "2.14.0",
"version": "2.15.0",
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
"author": "Umami Software, Inc. <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -69,11 +69,12 @@
"@dicebear/collection": "^9.2.1",
"@dicebear/core": "^9.2.1",
"@fontsource/inter": "^4.5.15",
"@prisma/client": "5.17",
"@prisma/client": "5.22.0",
"@prisma/extension-read-replicas": "^0.3.0",
"@react-spring/web": "^9.7.3",
"@tanstack/react-query": "^5.28.6",
"@umami/prisma-client": "^0.14.0",
"@umami/react-zen": "^0.16.0",
"@umami/redis-client": "^0.21.0",
"chalk": "^4.1.1",
"chart.js": "^4.4.2",
Expand All @@ -99,12 +100,11 @@
"kafkajs": "^2.1.0",
"maxmind": "^4.3.6",
"md5": "^2.3.0",
"moment-timezone": "^0.5.35",
"next": "14.2.10",
"next": "15.0.3",
"next-basics": "^0.39.0",
"node-fetch": "^3.2.8",
"npm-run-all": "^4.1.5",
"prisma": "5.17",
"prisma": "5.22.0",
"react": "^18.2.0",
"react-basics": "^0.125.0",
"react-beautiful-dnd": "^13.1.0",
Expand Down
3 changes: 1 addition & 2 deletions src/app/(main)/profile/TimezoneSetting.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useState } from 'react';
import { Dropdown, Item, Button, Flexbox } from 'react-basics';
import moment from 'moment-timezone';
import { useTimezone, useMessages } from 'components/hooks';
import { getTimezone } from 'lib/date';
import styles from './TimezoneSetting.module.css';

const timezones = moment.tz.names();
const timezones = Intl.supportedValuesOf('timeZone');

export function TimezoneSetting() {
const [search, setSearch] = useState('');
Expand Down
4 changes: 3 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Metadata } from 'next';
import Providers from './Providers';
import '@fontsource/inter/300.css';
import '@fontsource/inter/400.css';
import '@fontsource/inter/500.css';
import '@fontsource/inter/700.css';
import '@fontsource/inter/800.css';
import 'react-basics/dist/styles.css';
import 'styles/index.css';
import 'styles/variables.css';
import '@umami/react-zen/dist/styles.css';

export default function ({ children }) {
return (
Expand Down
12 changes: 10 additions & 2 deletions src/lib/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import moment from 'moment-timezone';
import {
addMinutes,
addHours,
Expand Down Expand Up @@ -105,8 +104,17 @@ const DATE_FUNCTIONS = {
},
};

export function isValidTimezone(timezone: string) {
try {
Intl.DateTimeFormat(undefined, { timeZone: timezone });
return true;
} catch (error) {
return false;
}
}

export function getTimezone() {
return moment.tz.guess();
return Intl.DateTimeFormat().resolvedOptions().timeZone;
}

export function parseDateValue(value: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import debug from 'debug';
import { Prisma } from '@prisma/client';
import prisma from '@umami/prisma-client';
import moment from 'moment-timezone';
import { formatInTimeZone } from 'date-fns-tz';
import { MYSQL, POSTGRESQL, getDatabaseType } from 'lib/db';
import { SESSION_COLUMNS, OPERATORS, DEFAULT_PAGE_SIZE } from './constants';
import { fetchWebsite } from './load';
Expand Down Expand Up @@ -75,7 +75,7 @@ function getDateSQL(field: string, unit: string, timezone?: string): string {

if (db === MYSQL) {
if (timezone) {
const tz = moment.tz(timezone).format('Z');
const tz = formatInTimeZone(new Date(), timezone, 'yyyy-MM-dd HH:mm:ss');
return `date_format(convert_tz(${field},'+00:00','${tz}'), '${MYSQL_DATE_FORMATS[unit]}')`;
}
return `date_format(${field}, '${MYSQL_DATE_FORMATS[unit]}')`;
Expand All @@ -90,7 +90,7 @@ function getDateWeeklySQL(field: string, timezone?: string) {
}

if (db === MYSQL) {
const tz = moment.tz(timezone).format('Z');
const tz = formatInTimeZone(new Date(), timezone, 'yyyy-MM-dd HH:mm:ss');
return `date_format(convert_tz(${field},'+00:00','${tz}'), '%w:%H')`;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/yup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from 'moment-timezone';
import * as yup from 'yup';
import { isValidTimezone } from 'lib/date';
import { UNIT_TYPES } from './constants';

export const TimezoneTest = yup
Expand All @@ -8,7 +8,7 @@ export const TimezoneTest = yup
.test(
'timezone',
() => `Invalid timezone`,
value => moment.tz.zone(value) !== null,
value => isValidTimezone(value),
);

export const UnitTypeTest = yup.string().test(
Expand Down
Loading

0 comments on commit fccb1dd

Please sign in to comment.