Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Change from bash date to perl #96

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

madprogramer
Copy link

@madprogramer madprogramer commented Oct 3, 2022

Last week I discovered that the YT-DL Script collection does not actually work on zsh on Darwin (OS X). Well, at least the Archiving scripts.

When the Archiving scripts check for 30 days before today in the --datebefore argument, the current implementation uses "$(date --date="30 days ago" +%Y%m%d) which is bash friendly on most Linux distros. This will raise an error on BSD derivates, i.e. for Mac users.

Because, on the other hand, BSD-derivatives like Darwin have a slightly different syntax for date-arithmetic:

date -j -v-30d

The further complication is that it's non-trivial to write code that will run on both bash and zsh because even checking for an equality condition is different.

So, my current "OS-agnostic" solution is to instead use date-arithmetic in perl to get the date.

PERL_DATE=$(perl -e 'my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - 30*86400);$year += 1900; $mon+= 1; printf ("%04d%02d%02d", $year, $mon, $mday)')

This implementation should cover more systems, without adding too much bloat to the code.

defder-su added a commit to defder-su/SaveMedia that referenced this pull request Dec 25, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant