ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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 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!
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.