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
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)
def printDateInfo(self, qDate): print('{0}/{1}/{2}'.format(qDate.day(), qDate.month(), qDate.year())) print('Short date: {}'.format(qDate.toString(Qt.DefaultLocaleShortDate))) print('Long date: {}'.format(qDate.toString(Qt.DefaultLocaleLongDate))) print('ISO Date: {}'.format(qDate.toString(Qt.ISODate))) print(SimpleDate(date=date(qDate.year(), qDate.month(), qDate.day()), time=time(19, 30, 59, 299000), tz='utc').timestamp) print(SimpleDate('2020-05-30 19:30:59.299', format='Y-m-d H:M(:S)?', tz='utc').timestamp)
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)
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)
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)
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)
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
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)
else: day_change = Back.RED + str(day_change) + ' %' + Style.RESET_ALL if week_change > 0: week_change = Back.GREEN + Style.BRIGHT + str( week_change) + ' %' + Style.RESET_ALL else: week_change = Back.RED + str(week_change) + ' %' + Style.RESET_ALL portfolio += value value_string = '{:,}'.format(round(value, 2)) table.add_row([ name + ' (' + symbol + ')', str(assets[symbol]), value_string, str(price), str(hour_change), str(day_change), str(week_change) ]) print(table) print() portfolio_value_string = '{:,}'.format(round(portfolio, 2)) print('Total Portfolio Value: ' + Style.BRIGHT + Back.GREEN + portfolio_value_string + Style.RESET_ALL) print() time = parser.isoparse(last_updated) last_updated_string = SimpleDate(time).convert(country='IN').naive.datetime print('API Results Last Updated on ' + str(last_updated_string)) print()
def test_naive_bug(self): now = SimpleDate(2013, 6, 10, debug=DEBUG) now.convert('PDT', debug=DEBUG) # threw exception
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)
import bot_config from features.football.football_site_parser import get_matches from features.instagram.insta_loader import fetch_insta_post_data from features.instagram.insta_post import InstaPost from test.constants_test import INSTAGRAM_PUBLIC_POST_LINK, INSTAGRAM_PRIVATE_POST_LINK from util.util_request import get_site_request_content @pytest.mark.parametrize( "insta_post", [ pytest.param( InstaPost( post_url=INSTAGRAM_PUBLIC_POST_LINK), marks=pytest.mark.xfail( SimpleDate().tzinfo.zone == 'Etc/UTC', reason="Instagram post from private account.")), pytest.param( InstaPost( post_url=INSTAGRAM_PRIVATE_POST_LINK), marks=pytest.mark.xfail( reason="Instagram post from private account."))], ids=[ "Instagram public post.", "Instagram private post."]) def test_insta_post_fetching_data(insta_post): """Test of fetching Instagram post data.""" fetch_insta_post_data(insta_post) assert_that(len(insta_post.media_urls) > 1, is_(equal_to(