#!/usr/local/bin/bash -e

command=$1; shift;

case $command in
    timefile)
    stat -f "%m" "$1"
    ;;
    
    timedate)
    date -j "+%s" "$1"
    ;;

    shift)
    amount=$1; shift;
    for file in "$@"
    do
      curtime=`stat -f "%m" "$file"`
      newtime=$(($curtime + $amount))
      echo touch -t `date -r $newtime "+%Y%m%d%H%M.%S"` "$file"
      touch -t `date -r $newtime "+%Y%m%d%H%M.%S"` "$file"
    done
    ;;

    *)
    echo "usage:" 1>&2
    echo "$0 timefile <filename>" 1>&2
    echo "    to print the timestamp of the file in seconds" 1>&2
    echo "$0 timedate [[[[[cc]yy]mm]dd]HH]MM[.ss]" 1>&2
    echo "    to print the timestamp of the specified date in seconds using date(1)" 1>&2
    echo "$0 shift <number of seconds> <file> ..." 1>&2
    echo "    move the given files so many seconds into the future (or past, if number is negative)" 1>&2
    ;;
    
esac

    
