Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented yourtime plugin #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Implemented yourtime plugin #64

wants to merge 1 commit into from

Conversation

Mause
Copy link

@Mause Mause commented Oct 25, 2012

Put simply, the yourtime plugin allows users to set their current timezone via;
.myzone gmt+8
and for other users to determine another users current time via
.yourtime Lord_DeathMatch

Currently uses user supplied timezone without extra computation; ie, dst is not accounted for.
If it must be implemented before you will merge, let me know :) (i am Lord_Deathmatch on IRC)

Exposes yourtime command, and identical setzone and myzone commands.
@Mause
Copy link
Author

Mause commented Oct 27, 2012

I have looked at the PyTZ library as you requested, and have thought about implementation. From the onset, however, i believe it would be too fiddly to implement correctly. Rather than having the user recall a simple number, the user must recall and correctly spell (harder for some than you might imagine) a timezone name, such as Australia/Perth

Example code follows

from datetime import datetime
from pytz import timezone, utc

utc_dt = datetime.now(utc)
loc_dt = utc_dt.astimezone(timezone('Australia/Perth'))
fmt = 'For Lord_DeathMatch it is %A in the month of %B, %I:%M%p %Z (%z)'
print loc_dt.strftime(fmt)

which outputs;
For Lord_DeathMatch it is Saturday in the month of October, 09:08PM WST (+0800)

which, compared to the current implementation is quite nice and small;

from datetime import timedelta, datetime, tzinfo

class GMT(tzinfo):
    def __init__(self, difference):
        self.difference = difference

    def utcoffset(self, dt):
        return timedelta(hours=self.difference) + self.dst(dt)

    def dst(self, dt):
        return timedelta(0)

print datetime.now(GMT(+8)).ctime()

which outputs
Sat Oct 27 21:09:29 2012

@Mause
Copy link
Author

Mause commented Oct 28, 2012

I have given it some thought, and i have resolved that this would be best implemented using PyTZ and a timezone listing hosted online that skybot refers users to when they input an invalid timezone.

@rmmh
Copy link
Owner

rmmh commented Oct 28, 2012

You could search PyTZ.common_timezones for a match to whatever the user entered.

Another idea is to fold this into the weather plugin, which already remembers locations that people passed it. The wunderground API results include a timezone field.

@Mause
Copy link
Author

Mause commented Nov 2, 2012

I would really rather not restrict users to simple the common time zones; i would rather use all_timezones instead (hackers are everywhere :P)

The weather plugin integration would be a little fiddlesome; if I had to use it, I would re-work it so that it uses a command that is shared between the weather plugin and the yourtime plugin. And such a command is already implemented in the yourtime plugin.

@Mause
Copy link
Author

Mause commented Nov 2, 2012

I just looked at the description for all_timezones and agree it would be more useful to use up to date timezones.

@rmmh rmmh force-pushed the master branch 2 times, most recently from d7ee24b to 6b23fe3 Compare October 22, 2015 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants