ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: z_time.py
Submitter: Stephen Chappell (other recipes)
Last Updated: 2006/07/06
Version no: 1.0
Category: Algorithms

 

Not Rated yet


Description:

This recipe emulates time from the fictional planet of Aens.
The code is meant to be a novelty and not for real programming.

Source: Text Source

'''Support module for Aens time conversion.

This module provides several functions that allow
conversion from earth seconds to Aens time units.'''

__version__ = 1.2

################################################################################

import time

def aens_seconds():
    'Return current Aens seconds.'
    return time.time() - 946684800

def aens_year(seconds):
    'Converts from seconds to years.'
    return int(seconds) / 29030400 + 1

def aens_season(seconds):
    'Converts from seconds to seasons.'
    return int(seconds) / 7257600 % 4 + 1

def aens_month(seconds):
    'Converts from seconds to months.'
    return int(seconds) / 2419200 % 3 + 1

def aens_week(seconds):
    'Converts from seconds to weeks.'
    return int(seconds) / 604800 % 4 + 1

def aens_day(seconds):
    'Converts from seconds to days.'
    return int(seconds) / 86400 % 7 + 1

def aens_alpha(seconds):
    'Converts from seconds to alphas.'
    return int(seconds % 86400 * 1000 / 86400)

def aens_beta(seconds):
    'Converts from seconds to betas.'
    return int(seconds % 86400 * 1000000 / 86400 % 1000)

def basic_format(seconds):
    'Converts from seconds to basic format.'
    return '.'.join((str(aens_year(seconds)), str(aens_season(seconds)), str(aens_month(seconds)), str(aens_week(seconds)), str(aens_day(seconds)), str(aens_alpha(seconds)).zfill(3), str(aens_beta(seconds)).zfill(3)))

def timer(seconds):
    'Prints time for specified number of seconds.'
    start = time.time()
    while time.time() - start <= seconds:
        print basic_format(aens_seconds())
        beta = aens_beta(aens_seconds())
        while beta == aens_beta(aens_seconds()):
            pass

################################################################################

if __name__ == '__main__':
    import sys
    print 'Content-Type: text/plain'
    print
    print file(sys.argv[0]).read()

Discussion:

A timer function is provided to visualize the passing of time on Aens.
The most I've been able to do with this module is use it to encode
timestamps.



Add comment

No comments.



Highest rated recipes:

1. A simple XML-RPC server

2. Web service accessible ...

3. IPy Notify

4. Changing return value ...

5. Quantum Superposition

6. Pickle objects under ...

7. Generalized delegates ...

8. Reorder a sequence (uses ...

9. Setting Win32 System ...

10. ObjectMerger




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.