From: Doug Knight <doug.knight@uaf.edu>
To: Martin Klier <martin.klier@atu.de>
Cc: linux-admin@vger.kernel.org
Subject: Re: Special date/cal needs eg. "thrid friday of july"
Date: Thu, 11 Jan 2007 11:26:20 -0900 [thread overview]
Message-ID: <45A69D6C.2070306@uaf.edu> (raw)
In-Reply-To: <200701111624.02217.martin.klier@atu.de>
Martin,
This script should give you enough information to figure out how to do what
you want. It is not intended to be used as written; it doesn't do any
syntax checking.
Throw the script in a file, mark it executable, and pass the date you're
looking, in the same format as third friday of july, on the command line.
(e.g. ./some_file third friday of july)
#!/bin/sh
# Parse input
week=$1
weekday=$2
month=$4
case "$week" in
[Ff][Ii][Rr][Ss][Tt])
skip_weeks=0;
;;
[Ss][Ee][Cc][Oo][Nn][Dd])
skip_weeks=1;
;;
[Tt][Hh][Ii][Rr][Dd])
skip_weeks=2;
;;
[Ff][Oo][Uu][Rr][Tt][Hh])
skip_weeks=3;
;;
[Ff][Ii][Ff][Tt][Hh])
skip_weeks=4;
;;
esac
# Convert the weekday to a number ( 1 = Monday, 2 = Tuesday, ... )
weekday_no=$( date -d "$weekday" +%u )
# Qualify the month with a year and a day (the first) for
# illustrative purposes
first_of_month=$( date -I -d "${month} 1" )
# Now that we're done formating the input, these three lines do the
# real work.
# Find the weekday number of the first day of the month
# (again 1 = Monday, ... )
first_weekday_no=$( date -d "${first_of_month} ${skip_weeks} weeks" +%u )
# Do some math; difference between desired weekdays + 7 then mod by 7.
let skip_days=(7+weekday_no-first_weekday_no)%7
# Use date to print the date. You can format if desired.
date -d "${first_of_month} ${skip_weeks} weeks ${skip_days} days"
Doug Knight
Martin Klier wrote:
> Hi Linux Admins,
>
> is there a command to get something like "thrid friday of july" or "second
> wednesday each month"? I crossread the manuals for date and gcal, but it
> seems to be impossible. Next thing I found was gcal, with
> "--period-of-fixed-dates", but I have not been able to get useful results,
> and
> date -d "35 tuesday" (35th tuesday of a year), but I have not been able to
> limit it to months nor selecting the year (by the way, I do not need it).
>
> Has somebody experience with this one, and can you give me a hint where to
> look, or even an example?
>
> Thanks a lot in advance,
next prev parent reply other threads:[~2007-01-11 20:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-11 15:23 Special date/cal needs eg. "thrid friday of july" Martin Klier
2007-01-11 16:56 ` Kirkwood, David A.
2007-01-11 17:47 ` Benoît Rouits
2007-01-11 20:26 ` Doug Knight [this message]
2007-01-12 15:02 ` Adam T. Bowen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45A69D6C.2070306@uaf.edu \
--to=doug.knight@uaf.edu \
--cc=linux-admin@vger.kernel.org \
--cc=martin.klier@atu.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.