Repository to merge (name): khandrish-evennia Revision to merge (URL to revision in your Clone's Changelist): https://code.google.com/r/khandrish-evennia/source/detail?r=f87899bb3328f638975599109a23deb99c573031
Reason for merge: Allows user to customize how often they want the gametime script to run and update the game time. This will allow for finer grained control over how the world behaves out of the box with very little effort.
Comment #1
Posted on Jan 2, 2014 by Massive HorseComment deleted
Comment #2
Posted on Jan 2, 2014 by Massive HorseDidn't want to make a whole other issue for it, but I've done some additional work on the gametime.py script.
Changes are as follows: - Added a default setting for the number of IC seconds per IC minute. - Modified formatting functions so that they respect the number of IC seconds per IC minute. - Part of formatting refactor was the creation/exposure of the format function. This is an easy hook for developers to get their own custom time tuples returned. This adds more flexibility for the manipulation of time out of the box. - More accurate, but still approximate for month and year, calculation for realtime
There shouldn't be any changes in this that break anything. However, given that the calculation for realtime changed there is always a possibility that this could have an impact somewhere. The original calculation was done on the assumption that a month was exactly 4 weeks long, and a year was exactly 12 months long. This ended up meaning a "realtime" year was actually only 336 days long.
The new algorithm calculates the seconds in a year based off of 365 days, and the seconds in a month as 1/12th of the previous value. Minutes, hours, days, and weeks are all calculated off of each other. A week is always 7 days, where a day is always 24 hours, and so on. This means all calculations going out, approximately, a month will be exact while anything over that will be an estimate, same as before but with more accuracy the further out you go.
This doesn't account for leap years but outside of getting fancier with calculations involving system time it's about as accurate as it's going to get, I think. the new commit incorporates the changes in the previous commit above and can be found here: https://code.google.com/r/khandrish-evennia/source/detail?r=b1bcfcbcdc852ac3a0f4e39fb4e1f8db87b7feb6
Comment #3
Posted on Jan 3, 2014 by Happy BearThanks for the contribution!
I agree the gametime module (which is quite old) needs reworking and I like your refactoring with the format() function; looks clean. I suspect the entire module needs fundamental rework of its functionality though. Relying on a short-enough update frequency is not an efficient solution when you want to access such data at irregular intervals.
The way to best refactor this module (I think) is likely to have the script calculate the current real-time/game-time/uptime on the fly whenever asked for it. This way it can be accessed as often as needed and with any precision without any database access overhead. The script's only duty then just becomes to regularly save the total game time so it is not lost if the server crashes unexpectedly. A 1-minute interval seems like enough precision for that purpose. How does that sound?
I'll keep this open for now and when I have time I'll whip up a refactor based on your merged code. Thanks again! :)
Comment #4
Posted on Jan 4, 2014 by Massive HorseI do like your suggestion about dynamically calculating the time. It really doesn't take any real computational effort, it's so much cleaner for so many reasons, and should cut down on resource utilization quite a bit.
Also, and I don't know why I didn't think of this before, but we can just do this for calculating exact times in the future for realtime and gametime conversions:
from datetime import datetime d = datetime.now() print d 2014-01-03 21:21:20.548727 from datetime import timedelta d2 = timedelta(seconds=34728) print d2 9:38:48
With datetime and all of the manipulation functions provided there the gametime module could become robust and be on it's way to providing for most temporal needs.
Comment #5
Posted on Jan 4, 2014 by Happy BearMerged, then modified. Implemented a new and revised version of gametime.py as per rc2a978238c8c. This one works on the fly and the server also makes sure to call it to save its time when it shuts down. I did not use the datetime module since I prefer to keep the main display formatting outside the module (it normally only outputs seconds, so it's possible the format keywords should be removed completely, instead relying on the string format functions in src.utils.utils for all conversion).
Status: Merged