Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show UTC in time column header #402

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 16 additions & 13 deletions packages/frontend/src/utils/formatting/formatTimestamp.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Timestamp } from '@explorer/types'

export function formatTimestamp(timestamp: Timestamp, type: 'local' | 'utc') {
const { datePart, timePart } = formatTimestampParts(timestamp, type)
// Right now we treat every timestamp as UTC because we are using SSR and there is currently no way to get the user's timezone
// If we ever add a way to get the user's timezone, we can add a 'local' type and retrieve the timezone from the headers or smth

export function formatTimestamp(timestamp: Timestamp) {
const { datePart, timePart } = formatTimestampParts(timestamp)
return `${datePart} ${timePart}`
}

export function formatTimestampParts(
timestamp: Timestamp,
type: 'local' | 'utc'
) {
export function formatTimestampParts(timestamp: Timestamp) {
const date = new Date(Number(timestamp))

const year = type === 'local' ? date.getFullYear() : date.getUTCFullYear()
const month = type === 'local' ? date.getMonth() + 1 : date.getUTCMonth() + 1
const day = type === 'local' ? date.getDate() : date.getUTCDate()
const hour = type === 'local' ? date.getHours() : date.getUTCHours()
const minute = type === 'local' ? date.getMinutes() : date.getUTCMinutes()
const second = type === 'local' ? date.getSeconds() : date.getUTCSeconds()
const year = date.getUTCFullYear()
const month = date.getUTCMonth() + 1
const day = date.getUTCDate()
const hour = date.getUTCHours()
const minute = date.getUTCMinutes()
const second = date.getUTCSeconds()

const YYYY = year.toString().padStart(4, '0')
const MM = month.toString().padStart(2, '0')
Expand All @@ -26,5 +26,8 @@ export function formatTimestampParts(
const mm = minute.toString().padStart(2, '0')
const ss = second.toString().padStart(2, '0')

return { datePart: `${YYYY}-${MM}-${DD}`, timePart: `${hh}:${mm}:${ss}` }
return {
datePart: `${YYYY}-${MM}-${DD}`,
timePart: `${hh}:${mm}:${ss}`,
}
}
2 changes: 1 addition & 1 deletion packages/frontend/src/view/components/TimeCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface TimeCellProps {
}

export function TimeCell({ timestamp }: TimeCellProps) {
const { datePart, timePart } = formatTimestampParts(timestamp, 'local')
const { datePart, timePart } = formatTimestampParts(timestamp)

return (
<div className="relative top-0.5 flex flex-col sm:top-0 sm:flex-row sm:gap-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface OfferEntry {

export function OffersTable(props: OffersTableProps) {
const columns: Column[] = [
{ header: 'Time' },
{ header: 'Time (UTC)' },
{ header: 'Id' },
{ header: 'Trade', align: 'center' },
...(props.showStatus ? [{ header: 'Status' }] : []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface TransactionEntry {
export function TransactionsTable(props: TransactionsTableProps) {
const columns: Column[] = []
if (!props.hideTime) {
columns.push({ header: 'Time' })
columns.push({ header: 'Time (UTC)' })
}
columns.push(
{ header: 'Tx Hash' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function ForcedTransactionsTable({
noRowsText="no forced transactions have been issued so far"
columns={[
{ header: 'Type' },
{ header: 'Time' },
{ header: 'Time (UTC)' },
{ header: 'Status' },
{ header: 'Tx Hash', monospace: true, fullWidth: true },
{ header: 'Position' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function ForcedTradeOffersTable({
columns={[
{ header: 'No.' },
{ header: 'Type' },
{ header: 'Time' },
{ header: 'Time (UTC)' },
{ header: 'Position' },
{ header: 'Amount', numeric: true, fullWidth: true },
{ header: 'Asset' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function PositionTransactionsTable(

const transactionHistoryTableColumns: Column[] = [
{ header: 'Type' },
{ header: 'Time' },
{ header: 'Time (UTC)' },
{ header: 'Status' },
{ header: 'Tx Hash', monospace: true, fullWidth: true },
{ header: 'Amount', numeric: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function StateUpdateDetails({
noRowsText="this update does not include any forced transactions"
columns={[
{ header: 'Type' },
{ header: 'Time' },
{ header: 'Time (UTC)' },
{ header: 'Tx Hash', monospace: true, fullWidth: true },
{ header: 'Amount', numeric: true },
{ header: 'Asset' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function StateUpdatesTable({ stateUpdates }: StateUpdatesTableProps) {
columns={[
{ header: 'No.' },
{ header: 'Tx Hash', monospace: true, fullWidth: true },
{ header: 'Time' },
{ header: 'Time (UTC)' },
{ header: 'Position updates', numeric: true },
{ header: 'Forced txs', numeric: true },
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function HomeStateUpdatesTable(props: HomeStateUpdatesTableProps) {
return (
<Table
columns={[
{ header: 'Time' },
{ header: 'Time (UTC)' },
{ header: 'Id' },
{ header: 'Tx Hash' },
{ header: 'Updates', numeric: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function StateUpdateStats(props: StateUpdateStatsProps) {
</Link>
</ValueItem>
<ValueItem label="Ethereum block timestamp">
{formatTimestamp(props.ethereumTimestamp, 'utc')} UTC
{formatTimestamp(props.ethereumTimestamp)} UTC
</ValueItem>

{/* Disabled until StarkEx timestamp will be fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function TransactionHistoryTable(props: TransactionHistoryTableProps) {
<SectionHeading title="History" />
<Table
columns={[
{ header: 'Time' },
{ header: 'Time (UTC)' },
{ header: 'Status' },
{ header: 'Description' },
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function TransactionOverview(props: TransactionOverviewProps) {
label={props.timestamp.label}
className="text-right"
>
{formatTimestamp(props.timestamp.timestamp, 'utc')} UTC{' '}
{formatTimestamp(props.timestamp.timestamp)} UTC{' '}
<span className="text-zinc-500">
({delayDays} {delayDays === 1 ? 'day' : 'days'})
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function UserBalanceChangesTable(props: UserBalanceChangesTableProps) {
return (
<Table
columns={[
{ header: 'Time' },
{ header: 'Time (UTC)' },
{ header: 'Update' },
{ header: 'Asset' },
{ header: 'Change', numeric: true },
Expand Down