mcpField
1
1k-date-formatting

1k-date-formatting

github.com/onekeyhqDevelopment2.5k70 installsUpdated today
Repository

About 1k-date-formatting

A coding skill for OneKey contributors that standardizes date and time formatting through shared utilities, options, and a React hook.

Key features

  1. 01Shared date and time utilities
  2. 02Relative date and distance formatting
  3. 03Custom format templates and options
  4. 04React hook for dynamic formatting
  5. 05Locale-aware formatting guidance

Use cases

  1. 01Formatting transaction history dates
  2. 02Displaying relative timestamps
  3. 03Applying a custom date format

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/onekeyhq/app-monorepo --skill 1k-date-formatting

After installing, type/1k-date-formattingin Claude Code to confirm it loaded.

Bundled filesreferences/rules/date-formatting.md

Details

From the project README

Date Formatting

Guidelines for consistent date and time formatting across OneKey applications.

Critical Rule

NEVER use native JavaScript date methods:

// ❌ FORBIDDEN
date.toLocaleDateString()
date.toLocaleString()
date.toISOString()
new Intl.DateTimeFormat().format(date)

// ✅ CORRECT
import { formatDate } from '@onekeyhq/shared/src/utils/dateUtils';
formatDate(date, { hideSeconds: true });

Quick Reference

FunctionUse CaseExample Output
formatDate(date, options?)Full date and time2024/01/15, 14:30
formatTime(date, options?)Time only14:30:45
formatRelativeDate(date)Relative displayToday, Yesterday
formatDistanceToNow(date)Time distance2 hours ago
formatDateFns(date, format?)Custom formatBased on template

Common Patterns

Transaction History
import { formatDate } from '@onekeyhq/shared/src/utils/dateUtils';

// Hide year if current year, hide seconds
<SizableText>
  {formatDate(item.createdAt, { hideTheYear: true, hideSeconds: true })}
</SizableText>
Custom Format
// Use format template
{formatDate(item.timestamp, { formatTemplate: 'yyyy-LL-dd HH:mm' })}
React Hook (for dynamic updates)
import useFormatDate from '@onekeyhq/kit/src/hooks/useFormatDate';

function MyComponent() {
  const { formatDate } = useFormatDate();
  return <SizableText>{formatDate(date, { hideSeconds: true })}</SizableText>;
}

Format Options

interface IFormatDateOptions {
  hideYear?: boolean;        // Always hide year
  hideMonth?: boolean;       // Always hide month
  hideTheYear?: boolean;     // Hide year if current year
  hideTheMonth?: boolean;    // Hide month if current month
  hideTimeForever?: boolean; // Hide time portion
  hideSeconds?: boolean;     // Hide seconds (HH:mm)
  formatTemplate?: string;   // Custom date-fns format
}

Detailed Guide

For comprehensive date formatting rules and examples, see date-formatting.md.

Topics covered:

  • Core utilities from @onekeyhq/shared/src/utils/dateUtils
  • Available formatting functions
  • Options reference and format templates
  • Common patterns for transactions, history, and relative time
  • React hooks for dynamic updates
  • Locale-aware formatting
  • Real-world examples
  • Troubleshooting

Key Files

PurposeFile Path
Core utilitiespackages/shared/src/utils/dateUtils.ts
React hookpackages/kit/src/hooks/useFormatDate.ts
Locale mappingpackages/shared/src/locale/dateLocaleMap.ts

Related Skills

  • /1k-i18n - Internationalization and locale handling
  • /1k-coding-patterns - General coding patterns

Comments

Markdown supported