Пример #1
0
 def test_convert(self):
     date1 = SimpleDate('2013-06-08 12:34:56.789 CLT', debug=True)
     # date1b = date1.convert(utc, debug=True)
     date2 = date1.convert(format='%Y/%m/%d', debug=True)
     assert str(date2) == '2013/06/08', str(date2)
     date3 = date1.convert('PST')
     assert str(date3) != '2013-06-08 12:34:56.789000 PST', str(date3)
     assert str(date3).endswith('PST'), str(date3)
     assert str(date3) == '2013-06-08 08:34:56.789000 PST', str(date3)
     date4 = SimpleDate('2013-06-14 13:14:17.295943 EDT').convert(country='GB')
     assert str(date4) == '2013-06-14 18:14:17.295943 BST', date4
Пример #2
0
 def test_12165691(self):
     now_utc = SimpleDate('2013-01-02 12:34:56', tz='UTC')
     now_tz = now_utc.convert(tz='CST6CDT')
     begin_day = now_tz.replace(hour=0, minute=0, second=0, microsecond=0)
     assert now_utc.timestamp == 1357130096, now_utc.timestamp
     assert now_tz.timestamp == 1357130096, now_tz.timestamp
     assert begin_day.timestamp == 1357106400, begin_day.timestamp
Пример #3
0
 async def time(self,ctx,timezone):
     """Query the time in a certain timezone."""
     for tz in pytz.all_timezones: #makes it case-insensitive
         if(timezone.lower() == tz.lower()):
             timezone = tz
     response = SimpleDate(tz=timezone,unsafe=True)
     format = str(response.convert(format='B d, Y - I:M p'))
     await ctx.send(format)
Пример #4
0
 def test_both(self):
     date = SimpleDate(2013, 2, 2, tz='CLST', debug=DEBUG)
     tz = DEFAULT_TZ_FACTORY.search('EST', country='US', datetime=date)
     target = date.datetime - date.datetime.utcoffset()
     target = target.replace(tzinfo=tz)
     target = tz.fromutc(target)
     assert str(target) == '2013-02-01 22:00:00-05:00', str(target)
     target = date.convert(tz)
     assert str(target) == '2013-02-01 22:00:00.000000 EST', str(target)
Пример #5
0
 def test_to2(self):
     date = SimpleDate(2013, 6, 2, tz=timezone('America/Santiago'), debug=DEBUG)
     tz = DEFAULT_TZ_FACTORY.search('EDT', country='US', datetime=date, debug=DEBUG)
     target = date.datetime - date.datetime.utcoffset()
     target = target.replace(tzinfo=tz)
     target = tz.fromutc(target)
     assert str(target) == '2013-06-02 00:00:00-04:00', str(target)
     target = date.convert(tz)
     assert str(target) == '2013-06-02 00:00:00.000000 EDT', str(target)
Пример #6
0
 def test_from(self):
     date = SimpleDate(2013, 2, 2, tz='CLST', debug=DEBUG)
     tz = timezone('America/New_York')
     target = date.datetime - date.datetime.utcoffset()
     target = target.replace(tzinfo=tz)
     target = tz.fromutc(target)
     assert str(target) == '2013-02-01 22:00:00-05:00', str(target)
     target = date.convert(tz)
     assert str(target) == '2013-02-01 22:00:00.000000 EST', str(target)
Пример #7
0
 def test_to(self):
     date = SimpleDate(2013, 2, 2, tz=timezone(u'America/Santiago'), debug=DEBUG)
     tz = DEFAULT_TZ_FACTORY.search(u'EST', country=u'US', datetime=date, debug=DEBUG)
     target = date.datetime - date.datetime.utcoffset()
     target = target.replace(tzinfo=tz)
     target = tz.fromutc(target)
     assert unicode(target) == u'2013-02-01 22:00:00-05:00', unicode(target)
     target = date.convert(tz)
     assert unicode(target) == u'2013-02-01 22:00:00.000000 EST', unicode(target)
Пример #8
0
class Timezones(commands.Cog):
    debug = False
    logging = False
    bottime = None

    def __init__(self,bot):
        print("TimeZones: Initialized")
        self.bot = bot
        self.timer.start()

    @commands.command()
    async def time(self,ctx,timezone):
        """Query the time in a certain timezone."""
        for tz in pytz.all_timezones: #makes it case-insensitive
            if(timezone.lower() == tz.lower()):
                timezone = tz
        response = SimpleDate(tz=timezone,unsafe=True)
        format = str(response.convert(format='B d, Y - I:M p'))
        await ctx.send(format)

    @commands.command()
    async def zonesearch(self,ctx,search):
        """Search for timezones with the given term"""
        if(search == None):
            await ctx.send("Please specify a search term.")
        search = search.lower()
        for tz in pytz.all_timezones:
            ttz = tz.lower()
            if(ttz.find(search)>=0):
                await ctx.send(tz)
        await ctx.send("Search complete!")

    @tasks.loop(seconds=1)
    async def timer(self):
        lasttime = self.bottime
        self.bottime = SimpleDate(tz='UTC')
        self.bottime = str(self.bottime.convert(format='B d, Y - I:M p'))
        if(self.logging == True and lasttime != self.bottime):
            await log(self,"Bottime updated: "+self.bottime)

    @commands.command()
    async def bottime(self,ctx):
        await ctx.send(self.bottime)
Пример #9
0
 def test_naive_bug(self):
     now = SimpleDate(2013, 6, 10, debug=DEBUG)
     now.convert('PDT', debug=DEBUG)  # threw exception