Special date/cal needs eg. "thrid friday of july"

Special date/cal needs eg. "thrid friday of july"

am 11.01.2007 16:23:59 von Martin Klier

--nextPart1911097.vUrFitDRvP
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi Linux Admins,

is there a command to get something like "thrid friday of july" or "second=
=20
wednesday each month"? I crossread the manuals for date and gcal, but it=20
seems to be impossible. Next thing I found was gcal, with=20
"--period-of-fixed-dates", but I have not been able to get useful results,=
=20
and=20
date -d "35 tuesday" (35th tuesday of a year), but I have not been able to=
=20
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=
=20
look, or even an example?

Thanks a lot in advance,
=2D-=20
Mit freundlichen Grüßen

i.A. Martin Klier
Systemadministration / Datenbanken
=2D--------------------------------------------------------- -------
A.T.U Auto-Teile-Unger
Handels GmbH & Co. KG

--nextPart1911097.vUrFitDRvP
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQBFplaSVKZfihvnEcQRAvZSAKCBhrcgy1J7jVTvQdLnnzpCjnR7AgCd EUfL
LFuta033/UXheIkpOeDQMKY=
=MC77
-----END PGP SIGNATURE-----

--nextPart1911097.vUrFitDRvP--
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

RE: Special date/cal needs eg. "thrid friday of july"

am 11.01.2007 17:56:23 von DAVID.A.KIRKWOOD

This method may be out of date, but if you add the CPAN for Date::Calc =
to a perl script you can write a script that will manipulate a given da=
te to add / subtract dates and give days of the week, months etc as out=
put or viseversa

David=20

-----Original Message-----
=46rom: linux-admin-owner@vger.kernel.org [mailto:linux-admin-owner@vge=
r.kernel.org] On Behalf Of Martin Klier
Sent: Thursday, January 11, 2007 10:24 AM
To: linux-admin@vger.kernel.org
Subject: Special date/cal needs eg. "thrid friday of july"

Hi Linux Admins,

is there a command to get something like "thrid friday of july" or "sec=
ond=20
wednesday each month"? I crossread the manuals for date and gcal, but i=
t=20
seems to be impossible. Next thing I found was gcal, with=20
"--period-of-fixed-dates", but I have not been able to get useful resul=
ts,=20
and=20
date -d "35 tuesday" (35th tuesday of a year), but I have not been able=
to=20
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=20
look, or even an example?

Thanks a lot in advance,
--=20
Mit freundlichen Grüßen

i.A. Martin Klier
Systemadministration / Datenbanken
------------------------------------------------------------ -----
A.T.U Auto-Teile-Unger
Handels GmbH & Co. KG
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Special date/cal needs eg. "thrid friday of july"

am 11.01.2007 18:47:54 von brouits

Hi

An example relative to this week:
ben@chimay:~ $ date -d "tuesday + 34 weeks"
[will give the next tuesday 34 weeks in the future]

An example relative to now
ben@chimay:~ $ date -d "now + 35 seconds - 3 days + 1 year"
[will give a dummy date in year 2008, based on "now" and some + and - ]

Other example
ben@chimay:~ $ date -d "3 days ago"
[no comment]

An absolute date:
ben@chimay:~ $ date -d "2007 1 jan"

could not find out how to mix absolute dates and '+' and '-'
HTH

Le jeudi 11 janvier 2007 à 16:23 +0100, Martin Klier a écrit =
:
> Hi Linux Admins,
>=20
> is there a command to get something like "thrid friday of july" or "s=
econd=20
> wednesday each month"? I crossread the manuals for date and gcal, but=
it=20
> seems to be impossible. Next thing I found was gcal, with=20
> "--period-of-fixed-dates", but I have not been able to get useful res=
ults,=20
> and=20
> date -d "35 tuesday" (35th tuesday of a year), but I have not been ab=
le to=20
> limit it to months nor selecting the year (by the way, I do not need =
it).
>=20
> Has somebody experience with this one, and can you give me a hint whe=
re to=20
> look, or even an example?
>=20
> Thanks a lot in advance,

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Special date/cal needs eg. "thrid friday of july"

am 11.01.2007 21:26:20 von Doug Knight

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,
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Special date/cal needs eg. "thrid friday of july"

am 12.01.2007 16:02:44 von adam.bowen

Hi,

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,

I love the --date GNU extension, but I tried a number of different
syntaxes to get it to do what you wanted without any luck. So I thought
a one line pipe would be fun:

cal 7 2007 | awk -F. 'NR > 2{print substr($1,5*3+1,2)}' | grep '[0-9]' |
awk 'NR == 3 {print $1}'

You set the day you're interested in through the first integer of the
second parameter of the substr call of the awk command. 0=Sunday
(0*3+1), 1=Monday (1*3+1) etc. You set the week number with the 'NR ==
n' part of the final awk. You set the month and year with the
parameters to cal. It invokes awk twice which if used in a very tight
loop could be a problem. It would be easy to merge the awk | grep | awk
into one awk command, but it starts to look more like program code on a
single line rather than a series of simple(-ish) commands.

Cheers

Adam
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html