Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
On Thu, Apr 08, 2004 at 02:27:00PM -0500, Mike Miller wrote:
> On Thu, 8 Apr 2004, Woodsmall, Ryan (IATS) wrote:
>
> > The Perl time stuff does NOT like dates before 1902 or after 2037. It
> > craps out. The first bit of code should work better for dates. I knew
> > there was a reason that I didn't just use the timelocal() stuff; I just
> > didn't know why... I promise.
>
> I believe you!
>
Because it's fun to compare languages, here's the Python version. Note I just
cut 'n' pasted your original math. Requires Python 2 or newer. (In RedHat 7.X
systems, this is installed at /usr/bin/python2)
#!/usr/bin/python
import time,sys,re
def compute_easter(y):
c = y / 100
n = y - 19 * ( y / 19 )
k = ( c - 17 ) / 25
i = c - c / 4 - ( c - k ) / 3 + 19 * n + 15
i = i - 30 * ( i / 30 )
i = i - ( i / 28 ) * ( 1 - ( i / 28 ) * ( 29 / ( i + 1 ) )
* ( ( 21 - n ) / 11 ) )
j = y + y / 4 + i + 2 - c + c / 4
j = j - 7 * ( j / 7 )
l = i - j
m = 3 + ( l + 40 ) / 44
d = l + 28 - 31 * ( m / 4 )
return (y,m,d,0,0,0,0,0,0)
def date_format(etime):
return time.strftime("%A, %b %d, %Y",time.localtime(time.mktime(etime)))
years=[]
args=sys.argv[1:]
if not args:
years.append(int(time.strftime('%Y')))
else:
for arg in args:
for regex in [re.compile(r'(\d+)\.\.(\d+)'),
re.compile(r'(\d+)-(\d+)'),
re.compile(r'(\d+)')]:
m=regex.match(arg)
if m:
years=years+range(int(m.groups()[0]),
1+int(m.groups()[-1]))
break
print "Easter falls on the following day%s:"%('s'*(not len(years)==1))
print '\n'.join(map(date_format,map(compute_easter,years)))
# This is the end of the program
--
To invent, you need a good imagination and a pile of junk. -Thomas Edison
_______________________________________________
discussion mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/discussion