LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-24-2006, 11:18 AM   #1
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
Perl: Converting a Calendar


I'm working on a small project for a friend's website that takes our modern calendar and converts it into a fictional calendar to be displayed on his webpage.

It'd be very easy were the dates similar, but of course nothing's that simple. The problem is the months are all either 30- or 29-days long, and start on March 20th.

I'm interested in converting a localtime result of March 20th for example into "1st day of the Hare," but am not interested in writing 366 (can't forget about leap years) seperate if/elsif statements.

Is there an easier way (and of course TMTOWTDI) to 'translate' the dates?

Sample calendar is as follows:
- Month1 -- March 20 - April 18
- Month2 -- April 19 - May 17
- Month3 -- May 18 - June 16
- Month4 -- June 17 - July 15
And so forth

Thanks
 
Old 06-25-2006, 11:04 AM   #2
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
Hi,
if you translate the dates to timestamps then you cant just add the diference and translate back. Which es basically my idea: to have the real date subtract (ot add) a fixed amount of time.

To work with dates you should check the faq number 4:

Code:
man perlfaq4
there look for the "Date" section and it will give you pointers. If my memory doesnt fail, I think there are some modules of your interest like Date::Calc, Time::Local. But I dont have them installed to check them :P

I hope this is useful
Cheers!
 
Old 06-25-2006, 02:47 PM   #3
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Original Poster
Rep: Reputation: 49
Thanks demon_vox!

I was looking last night at a Date::Convert module that may do the trick, but I won't be able to have it installed on the machine the script is running on. I'll poke a bit through the manpage and see what I can do -- this project really would have been easier had the months and days been the same, but of course, not everything is as easy as we'd like!

Thanks for the suggestion
 
Old 06-25-2006, 04:00 PM   #4
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Original Poster
Rep: Reputation: 49
Awesome suggestion! I think I have it figured out.

And, so if anyone else is interested in doing a similar thing, I converted everything to the equivalent day of the year; For example, if the 1st of the year is March 20th (as above), localtime[7]-79 will return 1, the first of the year. Then, as in the above example, 1-30 is Month1, 31-60 is Month2, et cetera. This not only gives the correct day of the year but also the correct month for later retrieval.

Wonderful!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
converting .vbs script to perl ? huxflux Programming 30 03-04-2006 09:18 AM
Converting perl to Binary DanTaylor Programming 3 02-02-2006 08:57 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
prompt based calendar program? Calendar? thebeaglebeagle Linux - Software 0 09-15-2003 01:10 PM
Converting perl files to executable mac files mrozkan Programming 0 04-16-2002 09:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration