#!/bin/sh
# leapyear simplified after gregorian calender
# def: leap year is evenly divisible by 4,
# but if it's also evenly divisible
# by 100 then it's not unless it's also evenly
# divisible by 400.
# source: somewhere on the Net :( I should have noted.
# return 0 or 1
# optional parameter for year if omitted current year is used
isLeapYear() {
# casevariable
leapyear=${1:-`date +%Y`}
case $leapyear in
*0[48] |\
*[2468][048] |\
*[13579][26] |\
*[13579][26]0|\
*[2468][048]00 |\
*[13579][26]00 ) return 0 ;;
*) return 1 ;;
esac
}
if isLeapYear $1
then
echo "yes"
else
echo "no"
fi
echo "$JAHR" | sed -n '/\([0-9][0-9]\(0[48]\|[2468][048]\|[13579][26]\)\|\(0[48]\|[2468][048]\|[13579][26]\)00\)/p'
echo "$JAHR" | awk '{if(($0 % 100 != 0)&&($0 % 4 == 0))print $0; else if($0 % 400 == 0)print$0}'
i=$JAHR; if [ $(($i % 100)) != 0 -a $(($i % 4)) == 0 ] ; then echo $i ; else if [ $(($i % 400)) == 0 ] ; then echo $i ; fi; fi
#!/usr/bin/env tclsh
# Aktuelles Jahr oder Jahr manuell angeben.
set year [clock format [clock seconds] -format {%Y}]
# set year 0900
# Schutz vor oktal Zahlen.
set year [scan $year %d]
# Wenn Jahr durch 400 teilbar ohne Rest muss es ein Schaltjahr sein.
if {[expr int($year.0 / 400)] == [expr $year.0 / 400]} {
puts "$year ist ein Schaltjahr."
exit 0
}
# Wenn Jahr durch 4 aber nicht durch 100 ohne Rest teilbar => Schaltjahr
if {[expr int($year.0 / 4)] == [expr $year.0 / 4] && [expr int($year.0 / 100)] != [expr $year.0 / 100]} {
puts "$year ist ein Schaltjahr."
exit 0
}
puts "$year kein Schaltjahr"
exit 0
#!/usr/bin/env tclsh
# Aktuelles Jahr oder Jahr manuell angeben.
#set year [clock format [clock seconds] -format {%Y}]
set year 1000
# Schutz vor oktal Zahlen.
set year [scan $year %d]
# Wenn Jahr durch 400 teilbar ohne Rest muss es ein Schaltjahr sein.
if {$year % 400 == 0} {
puts "$year ist ein Schaltjahr."
exit 0
}
# Wenn Jahr durch 4 aber nicht durch 100 ohne Rest teilbar => Schaltjahr
if {$year % 4 == 0 && $year % 100 != 0} {
puts "$year ist ein Schaltjahr."
exit 0
}
puts "$year kein Schaltjahr."
exit 0