Ejemplo n.º 1
0
def will_start(unixtime):
    date = datetime.fromtimestamp(int(unixtime), tz(timedelta(hours=9)))
    now = datetime.now(tz(timedelta(hours=9)))
    gap = date - now

    hours = int(gap.seconds / 3600)
    minutes = int(gap.seconds / 60) % 60

    if hours > 0:
        return '約{}時間'.format(hours)
    else:
        return '約{}分'.format(minutes)
Ejemplo n.º 2
0
    def update_events(self):
        feed = feedparser.parse(self.source.url)
        events = []
        for event in feed.entries:
            date = datetime.fromtimestamp(mktime(event['published_parsed']))
            date = timezone.make_aware(date, timezone=tz(timedelta(0)))
            event['published'] = date
            if date > self.source.lastVisited:
                events.append(event)
        self.process_events(events)

        date = datetime.fromtimestamp(mktime(feed.feed['updated_parsed']))
        date = timezone.make_aware(date, timezone=tz(timedelta(0)))
        self.source.lastVisited = date
        self.source.save()
Ejemplo n.º 3
0
 def test_get_interval_with_week_days_follows_timezone(self):
     tenant_uuids = None
     kwargs = {
         'from_': dt(2020, 9, 1, 0, 0, 0, tzinfo=tz(td(hours=12))),
         'week_days': [1, 2, 3, 4, 5],
         'timezone': 'Pacific/Auckland',
     }
     result = self.dao.queue_stat.get_interval(tenant_uuids, **kwargs)
     assert_that(result[0], has_entries(answered=1 + 4))
Ejemplo n.º 4
0
 def test_get_interval_with_start_end_time_follows_timezone(self):
     tenant_uuids = None
     kwargs = {
         'from_': dt(2020, 9, 1, 0, 0, 0, tzinfo=tz(td(hours=5))),
         'start_time': 9,  # = 4 UTC
         'end_time': 10,  # = 5 UTC
         'timezone': 'Asia/Karachi',
     }
     result = self.dao.queue_stat.get_interval(tenant_uuids, **kwargs)
     assert_that(result[0], has_entries(answered=2 + 3))
Ejemplo n.º 5
0
    def test_get_qos_intervals_on_dst_change_adds_number_of_calls(self):
        tenant_uuids = None
        kwargs = {
            'from_': dt(2020, 11, 1, 0, 0, 0, tzinfo=tz(td(hours=-4))),
            'until': dt(2020, 11, 1, 4, 0, 0, tzinfo=tz(td(hours=-5))),
            'qos_min': 0,
            'qos_max': 5,
            'start_time': 0,
            'end_time': 3,
            'timezone': 'America/Montreal',
        }
        result = self.dao.queue_stat.get_qos_interval_by_queue(
            tenant_uuids, 1, **kwargs)
        assert_that(result, has_entries(answered=2, abandoned=2))

        kwargs['qos_min'] = 5
        kwargs['qos_max'] = 20
        result = self.dao.queue_stat.get_qos_interval_by_queue(
            tenant_uuids, 1, **kwargs)
        assert_that(result, has_entries(answered=6, abandoned=2))
Ejemplo n.º 6
0
 def test_get_interval_with_start_end_time_follows_timezone_on_dst_threshold(
         self):
     tenant_uuids = None
     kwargs = {
         'from_': dt(2020, 11, 1, 0, 0, 0, tzinfo=tz(td(hours=-4))),
         'start_time': 1,
         'end_time': 3,
         'timezone': 'America/Montreal',
     }
     result = self.dao.queue_stat.get_interval(tenant_uuids, **kwargs)
     assert_that(result[0], has_entries(answered=2 + 3))
Ejemplo n.º 7
0
    def construct_from_code(cls, code):
        try:
            match = re.match(
                r'(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(([+\-])(\d{2})(\d{2}))?',
                code)
        except TypeError:
            raise ValueError(code)

        if match is None:
            raise ValueError(code)

        fields = match.groups()

        # datetime...
        year = int(fields[0])
        month = int(fields[1])
        day = int(fields[2])

        hour = int(fields[3])
        minute = int(fields[4])

        # no zone...
        if fields[5] is None:
            datetime = dt(year,
                          month,
                          day,
                          hour,
                          minute,
                          0,
                          0,
                          tzinfo=pytz.timezone('Etc/UTC'))

            return AQCSVDatetime(datetime)

        # zone...
        zone_sign = -1 if fields[6] == '-' else 1
        zone_hours = int(fields[7])
        zone_mins = int(fields[8])

        zone_offset = zone_sign * td(hours=zone_hours, minutes=zone_mins)
        reporting_zone = tz(zone_offset)

        datetime = dt(year,
                      month,
                      day,
                      hour,
                      minute,
                      0,
                      0,
                      tzinfo=reporting_zone)

        return AQCSVDatetime(datetime, reporting_zone)
 def test_get_interval_with_week_days_follows_timezone(self):
     tenant_uuids = None
     kwargs = {
         'from_': dt(2020, 9, 1, 0, 0, 0, tzinfo=tz(td(hours=12))),
         'week_days': [1, 2, 3, 4, 5],
         'timezone': 'Pacific/Auckland',
     }
     result = self.dao.agent_stat.get_interval(tenant_uuids, **kwargs)
     assert_that(
         result,
         contains_inanyorder(
             has_entries(
                 agent_id=42,
                 agent_number='1001',
                 answered=2,
                 conversation_time=td(seconds=11 + 654).seconds,
                 login_time=td(hours=1 + 1).seconds,
             ), ),
     )
 def test_get_interval_with_start_end_time_follows_timezone(self):
     tenant_uuids = None
     kwargs = {
         'start_time': 9,  # = 4 UTC
         'end_time': 10,  # = 5 UTC
         'from_': dt(2020, 9, 1, 0, 0, 0, tzinfo=tz(td(hours=5))),
         'timezone': 'Asia/Karachi',
     }
     result = self.dao.agent_stat.get_interval(tenant_uuids, **kwargs)
     assert_that(
         result,
         contains_inanyorder(
             has_entries(
                 agent_id=42,
                 agent_number='1001',
                 answered=1,
                 conversation_time=td(seconds=12).seconds,
                 login_time=td(minutes=30).seconds,
             ), ),
     )
 def test_get_interval_with_start_end_time_follows_timezone_on_dst_threshold(
         self):
     tenant_uuids = None
     kwargs = {
         'start_time': 1,  # = 5 UTC
         'end_time': 3,  # = 8 UTC
         'from_': dt(2020, 11, 1, 0, 0, 0, tzinfo=tz(td(hours=-4))),
         'timezone': 'America/Montreal',
     }
     result = self.dao.agent_stat.get_interval(tenant_uuids, **kwargs)
     assert_that(
         result,
         contains_inanyorder(
             has_entries(
                 agent_id=42,
                 agent_number='1001',
                 answered=2,
                 conversation_time=td(seconds=12 + 11).seconds,
                 login_time=td(hours=1, minutes=30).seconds,
             ), ),
     )
Ejemplo n.º 11
0
class TestTimezoneRequirements(TestRequirements):
    cases = (('2017-05-06', dt(2017, 5, 6)), ('2017-05-06Z',
                                              dt(2017, 5, 6, tzinfo=tz.utc)),
             ('2017-05-06+01:30',
              dt(2017, 5, 6, tzinfo=tz(td(hours=1, minutes=30)))),
             ('2017-05-06+0130',
              dt(2017, 5, 6,
                 tzinfo=tz(td(hours=1,
                              minutes=30)))), ('2017-05-06+01',
                                               dt(2017,
                                                  5,
                                                  6,
                                                  tzinfo=tz(td(hours=1)))),
             ('2017-05-06-01:30',
              dt(2017, 5, 6, tzinfo=tz(-td(hours=1, minutes=30)))),
             ('2017-05-06-0130',
              dt(2017, 5, 6, tzinfo=tz(-td(hours=1, minutes=30)))),
             ('2017-05-06-01', dt(2017, 5, 6, tzinfo=tz(-td(hours=1)))))
Ejemplo n.º 12
0
from datetime import timedelta, timezone as tz, datetime as dt
from functools import partial

from utils import *

import discord
from discord.ext import commands

# hackathon time zone
cst = tz(timedelta(hours=-5))  # cst is 5h behind utc

# hackathon start and end times
<<<<<<< HEAD
start = dt.fromtimestamp(1635613200, tz=cst)  # 12pm cst oct 30 2021
end = dt.fromtimestamp(1635699600, tz=cst)  # 12pm cst oct 31 2021

austin = partial(dt.now, tz=cst)  # gives current time in austin, use instead of dt.now() for uniformity

# October 30-31, 2021
# event format is (time, event name, event link if available)
sched = {
    30: [
=======
start = dt.fromtimestamp(1620481500, tz=cst)  # 8:45am cst may 8 2021
end = dt.fromtimestamp(1620579600, tz=cst)  # 12pm cst may 9 2021

austin = partial(dt.now, tz=cst)  # gives current time in austin, use instead of dt.now() for uniformity

# May 8-9, 2021
# event format is (time, event name, event link if available)
sched = {
Ejemplo n.º 13
0
# -*- coding: utf-8 -*-

from collections import namedtuple
from functools import wraps
from typing import Callable
from enum import IntEnum
from time import time_ns
from string import ascii_letters, digits
from random import choice
from datetime import (datetime as dt, timezone as tz, timedelta as td)

__all__ = ('get_timestamp', '_isdecimal', 'rstring', 'async_cache',
           'TimeScale', 'timef')

ts_fmt = ('%I:%M:%S%p', '%d/%m/%Y %I:%M:%S%p')
tz_est = tz(td(hours=-5), 'EST')  # TODO: fix for edt switch lol


def get_timestamp(full: bool = False) -> str:
    return f'{dt.now(tz = tz_est):{ts_fmt[full]}}'


def _isdecimal(s: str, _float: bool = False, _negative: bool = False) -> None:
    if _float:
        s = s.replace('.', '', 1)

    if _negative:
        s = s.replace('-', '', 1)

    return s.isdecimal()
Ejemplo n.º 14
0
def tzconv(zt, des='JST', aux='UTC'):
    if aux == 'JST':
        x = zt.astimezone(tz(dl(hours=+9)))
    return x
Ejemplo n.º 15
0
Also belle from KnightHacks
https://github.com/aadibajpai
https://github.com/lienne
'''


from datetime import timedelta, timezone as tz, datetime as dt
from functools import partial

from utils import paginate_embed

import discord
from discord.ext import commands

#est is 4hrs ahead of utc
est = tz(timedelta(hours = -4))

start = dt.fromtimestamp(1612000800, tz = est)
end = dt.fromtimestamp(1612101600, tz = est) 

orl = partial(dt.now, tz = est)


sched = {
    30: [
        ('10:00 am', 'Opening Ceremony', ''),
        ('10:30 am', 'Hacking Starts!!!', ''),
        ('10:30 am', 'Boss of the SOC (Splunk)', ''),
        ('12:30 am', 'Azure Skills Workshop', ''),
        ('1:00 pm', 'Recruiting Sesssion (Softdocs)', ''),
        ('1:30 pm', 'Trivia', ''),
Ejemplo n.º 16
0
def utc2jst(zt):
    #	x = zt.replace(tzinfo=dateutil.tz.tzlocal())
    x = zt.astimezone(tz.utc)
    #	print( x.tzinfo ) #d
    x = x.astimezone(tz(dl(hours=+9)))
    return x
Ejemplo n.º 17
0

@pytest.mark.parametrize(
    "string, expected",
    [
        ("1979-05-27T07:32:00", dt(1979, 5, 27, 7, 32, 0)),
        ("1979-05-27T07:32:00Z", dt(1979, 5, 27, 7, 32, 0, tzinfo=_utc)),
        (
            "1979-05-27T07:32:00-07:00",
            dt(1979,
               5,
               27,
               7,
               32,
               0,
               tzinfo=tz(td(seconds=-7 * 3600), "-07:00")),
        ),
        (
            "1979-05-27T00:32:00.999999-07:00",
            dt(
                1979,
                5,
                27,
                0,
                32,
                0,
                999999,
                tzinfo=tz(td(seconds=-7 * 3600), "-07:00"),
            ),
        ),
    ],