Skip to content

Commit

Permalink
Merge pull request #20 from ismaell/bsd-date-compat
Browse files Browse the repository at this point in the history
Fix usage of the date command on BSD systems
  • Loading branch information
mvertes authored Jun 3, 2020
2 parents cad74a9 + b9ee936 commit c69d773
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
12 changes: 10 additions & 2 deletions bookman
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,18 @@ do
esac
done
shift $(($OPTIND - 1))

# Compatibility wrapper for BSD/GNU date, for parsing dates
if date -j >/dev/null 2>&1; then
pdate() { date -u -j -f '@%s' "$@"; }
else
pdate() { date -u -d "$@"; }
fi

if [ -n "$SOURCE_DATE_EPOCH" ]; then
date=$(LC_ALL=C date -u -d "@$SOURCE_DATE_EPOCH" +'%d %B %Y')
date=$(LC_ALL=C pdate "@$SOURCE_DATE_EPOCH" +'%d %B %Y')
fi
date=${date:-$(date +'%d %B %Y')}
date=${date:-$(LC_ALL=C date -u +'%d %B %Y')}

[ $1 ] || set -- $(while read REPLY; do echo "$REPLY"; done)

Expand Down
12 changes: 10 additions & 2 deletions src2man
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,18 @@ do
esac
done
shift $(($OPTIND - 1))

# Compatibility wrapper for BSD/GNU date, for parsing dates
if date -j >/dev/null 2>&1; then
pdate() { date -u -j -f '@%s' "$@"; }
else
pdate() { date -u -d "$@"; }
fi

if [ -n "$SOURCE_DATE_EPOCH" ]; then
date=$(LC_ALL=C date -u -d "@$SOURCE_DATE_EPOCH" +'%d %B %Y')
date=$(LC_ALL=C pdate "@$SOURCE_DATE_EPOCH" +'%d %B %Y')
fi
date=${date:-$(date +'%d %B %Y')}
date=${date:-$(LC_ALL=C date -u +'%d %B %Y')}

#
# Extract manpages from source files. Man page content is enclosed in
Expand Down
12 changes: 10 additions & 2 deletions txt2man
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,18 @@ do
esac
done
shift $(($OPTIND - 1))

# Compatibility wrapper for BSD/GNU date, for parsing dates
if date -j >/dev/null 2>&1; then
pdate() { date -u -j -f '@%s' "$@"; }
else
pdate() { date -u -d "$@"; }
fi

if [ -n "$SOURCE_DATE_EPOCH" ]; then
date=$(LC_ALL=C date -u -d "@$SOURCE_DATE_EPOCH" +'%d %B %Y')
date=$(LC_ALL=C pdate "@$SOURCE_DATE_EPOCH" +'%d %B %Y')
fi
date=${date:-$(LC_ALL=C date +'%d %B %Y')}
date=${date:-$(LC_ALL=C date -u +'%d %B %Y')}

if test "$doprobe"
then
Expand Down

0 comments on commit c69d773

Please sign in to comment.