0.1.2 • Published 7 months ago

fix-ai-time v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

fix-ai-time

A git pre-commit hook that automatically updates dates (YYYY-MM-DD) in modified lines to the current date.

Why?

For some projects, any new date added to docs can be safely assumed to be intended to be a version of 'now' that aligns with the time the code was committed.

If your changelog or 'last updated' field is being autogenerated by AI, your timestamp is likely to be wrong. This is a simple hack to make sure it's always corrected on commit.

fix-ai-time finds dates in newly modified lines and updating them to the current date.

Warning

This is a dumb hack with a significant limitation: it will update ALL dates in any modified lines to today's date, even if those dates are legitimate historical dates that shouldn't be changed.

For example, if you edit a line containing:

Project started: 2020-01-01, Last updated: 2025-01-01

Both dates will be changed to today's date, even though the start date should have been preserved.

Only use this if: 1. You're specifically fixing AI-generated dates 2. You're certain that any dates in the lines you're modifying should be today's date 3. You've reviewed the changes before committing

Future versions will be smarter about which dates to update.

Installation & Setup

  1. Install the package:
npm install --save-dev fix-ai-time
  1. Create the git hooks directory:
mkdir -p .husky
  1. Create the pre-commit hook:
echo '#!/bin/sh

# Run fix-ai-time on pre-commit
node node_modules/fix-ai-time/index.js' > .husky/pre-commit

chmod +x .husky/pre-commit
  1. Configure git to use the hooks:
git config core.hooksPath .husky

How It Works

When you make a commit, fix-ai-time: 1. Examines the git diff of staged changes 2. Finds YYYY-MM-DD dates in newly added or modified lines 3. Updates any dates that are in the past to today's date 4. Automatically stages the changes

For example, if an AI generated this line:

Last updated: 2024-03-20  # AI using old training data

It will automatically become:

Last updated: 2025-01-03  # Today's actual date

Only dates in modified lines are updated, and only if they're in the past. Future dates are assumed to be intentional and are preserved.

Configuration

Create a fix-ai-time.config.js in your project root:

export default {
  // File extensions to process
  fileExtensions: ['.md', '.mdx', '.html', '.js', '.jsx', '.ts', '.tsx'],
  
  // Custom date pattern (default: YYYY-MM-DD)
  datePattern: /\b\d{4}-\d{2}-\d{2}\b/g,
  
  // Include time in timestamps (default: false)
  includeTime: true,
  
  // Customize the timestamp format
  formatTimestamp: () => {
    const now = new Date();
    return {
      date: now.toISOString().split('T')[0],
      time: now.toISOString().split('T')[1].split('.')[0]
    };
  }
}

Configuration Options

  • fileExtensions: Array of file extensions to process
  • datePattern: Regular expression to match dates
  • includeTime: Whether to include time in the timestamp (default: false)
  • formatTimestamp: Function that must return an object with:
    • date: String in YYYY-MM-DD format
    • time: String in HH:mm:ss format

Example valid formatTimestamp:

formatTimestamp: () => ({
  date: '2024-03-21',  // Must be YYYY-MM-DD
  time: '14:30:00'     // Must be HH:mm:ss
})

When includeTime is true, dates will be formatted as YYYY-MM-DDTHH:mm:ss.

Supported File Types

By default, fix-ai-time processes files with these extensions:

  • .md
  • .mdx
  • .html
  • .js
  • .jsx
  • .ts
  • .tsx

Skipping the Hook

To skip the hook for a particular commit:

git commit --no-verify

License

MIT

Contributing

Issues and pull requests welcome!

0.1.2

7 months ago

0.1.1

7 months ago