agentleFS
agentsdanceagentsdance/agentskills/skills/date-time-helper/SKILL.md

date-time-helper

Skill3 starsChanged 11 months agoApache-2.0View on GitHub

Work with dates, times, and timezones. Use when the user needs to format dates, calculate time differences, or handle timezone conversions.

The file

Files
SKILL.md

Date Time Helper

Handle dates, times, and timezone operations.

JavaScript Date Formatting

Native Intl API

const date = new Date();

// Basic formatting
date.toLocaleDateString('en-US');  // "1/15/2024"
date.toLocaleTimeString('en-US');  // "10:30:00 AM"
date.toLocaleString('en-US');      // "1/15/2024, 10:30:00 AM"

// Custom options
date.toLocaleDateString('en-US', {
  weekday: 'long',
  year: 'numeric',
  month: 'long',
  day: 'numeric',
});  // "Monday, January 15, 2024"

// Relative time
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
rtf.format(-1, 'day');   // "yesterday"
rtf.format(2, 'hour');   // "in 2 hours"

date-fns Library

import {
  format,
  formatDistance,
  formatRelative,
  addDays,
  subMonths,
  differenceInDays,
  isAfter,
  isBefore,
  parseISO,
} from 'date-fns';

// Formatting
format(new Date(), 'yyyy-MM-dd');           // "2024-01-15"
format(new Date(), 'MMMM do, yyyy');        // "January 15th, 2024"
format(new Date(), 'h:mm a');               // "10:30 AM"

// Relative
formatDistance(new Date(), subMonths(new Date(), 2));  // "2 months"
formatRelative(addDays(new Date(), 1), new Date());    // "tomorrow at 10:30 AM"

// Manipulation
addDays(new Date(), 7);      // 7 days from now
subMonths(new Date(), 3);    // 3 months ago

// Comparison
differenceInDays(date1, date2);  // Number of days between
isAfter(date1, date2);           // true/false
isBefore(date1, date2);          // true/false

// Parse ISO string
parseISO('2024-01-15T10:30:00Z');

Timezone Handling

// Get user's timezone
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;  // "America/New_York"

// Format in specific timezone
new Date().toLocaleString('en-US', {
  timeZone: 'Europe/London',
  dateStyle: 'full',
  timeStyle: 'long',
});

// Using date-fns-tz
import { formatInTimeZone, zonedTimeToUtc, utcToZonedTime } from 'date-fns-tz';

formatInTimeZone(new Date(), 'America/New_York', 'yyyy-MM-dd HH:mm:ss zzz');
// "2024-01-15 10:30:00 EST"

Common Patterns

Duration Formatting

function formatDuration(seconds) {
  const hours = Math.floor(seconds / 3600);
  const minutes = Math.floor((seconds % 3600) / 60);
  const secs = seconds % 60;

  if (hours > 0) return `${hours}h ${minutes}m`;
  if (minutes > 0) return `${minutes}m ${secs}s`;
  return `${secs}s`;
}

Time Ago

function timeAgo(date) {
  const seconds = Math.floor((Date.now() - date.getTime()) / 1000);

  const intervals = [
    { label: 'year', seconds: 31536000 },
    { label: 'month', seconds: 2592000 },
    { label: 'day', seconds: 86400 },
    { label: 'hour', seconds: 3600 },
    { label: 'minute', seconds: 60 },
  ];

  for (const interval of intervals) {
    const count = Math.floor(seconds / interval.seconds);
    if (count >= 1) {
      return `${count} ${interval.label}${count > 1 ? 's' : ''} ago`;
    }
  }
  return 'just now';
}

ISO 8601 Format

// Always store/transmit dates in ISO format
new Date().toISOString();  // "2024-01-15T10:30:00.000Z"

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.