mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-27 03:06:24 -05:00
feat(gui): Display developer responses to feedback (#302)
This commit is contained in:
parent
f1e5cdfbfe
commit
53a994e6dc
19 changed files with 1216 additions and 45 deletions
|
|
@ -74,4 +74,61 @@ export function bytesToMb(bytes: number): number {
|
|||
/// Get the markup of a maker's exchange rate compared to the market rate in percent
|
||||
export function getMarkup(makerPrice: number, marketPrice: number): number {
|
||||
return (makerPrice - marketPrice) / marketPrice * 100;
|
||||
}
|
||||
|
||||
// Updated function to parse 9-element tuple and format it
|
||||
export function formatDateTime(dateTime: [number, number, number, number, number, number, number, number, number] | null | undefined): string {
|
||||
if (!dateTime || !Array.isArray(dateTime) || dateTime.length !== 9) {
|
||||
// Basic validation for null, undefined, or incorrect structure
|
||||
return "Invalid Date Input";
|
||||
}
|
||||
|
||||
try {
|
||||
const [year, dayOfYear, hour, minute, second, nanoseconds, offsetH, offsetM, offsetS] = dateTime;
|
||||
|
||||
// More robust validation (example)
|
||||
if (year < 1970 || dayOfYear < 1 || dayOfYear > 366 || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59 || nanoseconds < 0 || nanoseconds > 999999999) {
|
||||
return "Invalid Date Components";
|
||||
}
|
||||
|
||||
// Calculate total offset in seconds (handle potential non-zero offsets)
|
||||
const totalOffsetSeconds = (offsetH * 3600) + (offsetM * 60) + offsetS;
|
||||
|
||||
// Calculate milliseconds from nanoseconds
|
||||
const milliseconds = Math.floor(nanoseconds / 1_000_000);
|
||||
|
||||
// Create Date object for the start of the year *in UTC*
|
||||
const date = new Date(Date.UTC(year, 0, 1)); // Month is 0-indexed (January)
|
||||
|
||||
// Add (dayOfYear - 1) days to get the correct date *in UTC*
|
||||
date.setUTCDate(date.getUTCDate() + dayOfYear - 1);
|
||||
|
||||
// Set the time components *in UTC*
|
||||
date.setUTCHours(hour);
|
||||
date.setUTCMinutes(minute);
|
||||
date.setUTCSeconds(second);
|
||||
date.setUTCMilliseconds(milliseconds);
|
||||
|
||||
// Adjust for the timezone offset to get the correct UTC time
|
||||
// Subtract the offset because Date.UTC assumes UTC, but the components might be for a different offset
|
||||
date.setTime(date.getTime() - totalOffsetSeconds * 1000);
|
||||
|
||||
// Final validation
|
||||
if (isNaN(date.getTime())) {
|
||||
return "Invalid Calculated Date";
|
||||
}
|
||||
|
||||
// Format to a readable string (e.g., "YYYY-MM-DD HH:MM:SS UTC")
|
||||
const yyyy = date.getUTCFullYear();
|
||||
const mm = String(date.getUTCMonth() + 1).padStart(2, '0');
|
||||
const dd = String(date.getUTCDate()).padStart(2, '0');
|
||||
const HH = String(date.getUTCHours()).padStart(2, '0');
|
||||
const MM = String(date.getUTCMinutes()).padStart(2, '0');
|
||||
const SS = String(date.getUTCSeconds()).padStart(2, '0');
|
||||
|
||||
return `${yyyy}-${mm}-${dd} ${HH}:${MM}:${SS} UTC`;
|
||||
|
||||
} catch (e) {
|
||||
return "Invalid Date Format";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue