Example #1
0
    def get_seconds_to_market_opening(self, from_time):
        """Return the amount of seconds from now to the next market opening,
        taking into account UK bank holidays and weekends"""
        today_opening = datetime(
            year=from_time.year,
            month=from_time.month,
            day=from_time.day,
            hour=8,
            minute=0,
            second=0,
            microsecond=0,
        )

        if from_time < today_opening and BankHolidays().is_work_day(from_time.date()):
            nextMarketOpening = today_opening
        else:
            # Get next working day
            nextWorkDate = BankHolidays().get_next_work_day(date=from_time.date())
            nextMarketOpening = datetime(
                year=nextWorkDate.year,
                month=nextWorkDate.month,
                day=nextWorkDate.day,
                hour=8,
                minute=0,
                second=0,
                microsecond=0,
            )
        # Calculate the delta from from_time to the next market opening
        return (nextMarketOpening - from_time).total_seconds()
Example #2
0
 def test_holidays_use_backup_data(self, mock_logger):
     with responses.RequestsMock() as rsps:
         rsps.add(rsps.GET, BankHolidays.source_url, status=404)
         bank_holidays = BankHolidays()
     mock_logger.warning.assert_called_once_with(
         'Using backup bank holiday data')
     self.assertTrue(bank_holidays.get_holidays())
Example #3
0
def bankhols(date):
    bankhols = BankHolidays()
    print("printed")
    for bank_holiday in bankhols.get_holidays():
        if bank_holiday['date'] == date:
            print("Dupa bo: " + str(bank_holiday['date']) + " - " + str(bank_holiday['title']))
            return False
    else:
        return True
Example #4
0
def bankhols(date):

    dat = datetime.strptime(date, "%d-%m-%Y")
    christmas = datetime(today.year, 12, 23)

    bankhols = BankHolidays()
    print("printed")



    for bank_holiday in bankhols.get_holidays():
        if bank_holiday['date'] == date:
            print("Dupa bo: " + str(bank_holiday['date']) + " - " + str(bank_holiday['title']))
            return False
    else:
        return True
Example #5
0
 def forbiddenDates(self):

        bankhols = BankHolidays()
        christmas = datetime(today.year, 12, 23)

        while True:
            if self.date >= christmas and self.date < datetime(today.year + 1, 1, 2):
                self.date = self.date + timedelta(days=+1)
                print("Wrong date", self.date)
            elif self.date.isoweekday() == 6 or self.date.isoweekday() == 7:
                self.date = self.date + timedelta(days=+1)
            else:
                for bank_holiday in bankhols.get_holidays():
                    if bank_holiday['date'].strftime("%d-%m-%Y") == self.date.strftime("%d-%m-%Y"):
                        print("Wrong date because: " + str(bank_holiday['date']) + " - " + str(bank_holiday['title']))
                        return False
                else:
                    return self.date
Example #6
0
def get_bank_holidays():

    # TODO sloooooow
    bank_holiday_dates = []
    bank_holidays = BankHolidays()

    # Hacky mess to convert dates to datetimes, localised to utc
    for bank_holiday in bank_holidays.get_holidays():
        # print(bank_holiday['title'], '>', bank_holiday['date'])
        bank_holiday_dates.append(
            pytz.utc.localize(
                datetime(bank_holiday['date'].year,
                         bank_holiday['date'].month,
                         bank_holiday['date'].day)
            )
        )

    return bank_holiday_dates
Example #7
0
 def is_market_open(self, timezone):
     """
     Return True if the market is open, false otherwise
         - **timezone**: string representing the timezone
     """
     tz = pytz.timezone(timezone)
     now_time = datetime.now(tz=tz).strftime("%H:%M")
     return BankHolidays().is_work_day(datetime.now(tz=tz)) and Utils.is_between(
         str(now_time), ("07:55", "16:35")
     )
Example #8
0
def test_is_market_open():
    timezone = "Europe/London"
    tz = pytz.timezone(timezone)
    now_time = datetime.now(tz=tz).strftime("%H:%M")
    expected = Utils.is_between(
        str(now_time),
        ("07:55", "16:35")) and BankHolidays().is_work_day(datetime.now(tz=tz))

    result = Utils.is_market_open(timezone)

    assert result == expected
Example #9
0
from app import convert_to_boolean, current_service, service_api_client
from app.extensions import zendesk_client
from app.main import main
from app.main.forms import (
    FeedbackOrProblem,
    SupportRedirect,
    SupportType,
    Triage,
)
from app.models.feedback import (
    GENERAL_TICKET_TYPE,
    PROBLEM_TICKET_TYPE,
    QUESTION_TICKET_TYPE,
)

bank_holidays = BankHolidays(use_cached_holidays=True)


@main.route('/support', methods=['GET', 'POST'])
def support():

    if current_user.is_authenticated:
        form = SupportType()
        if form.validate_on_submit():
            return redirect(
                url_for(
                    '.feedback',
                    ticket_type=form.support_type.data,
                ))
    else:
        form = SupportRedirect()
Example #10
0
 def get_bank_holidays_using_local_data(cls, **kwargs):
     with responses.RequestsMock() as rsps:
         rsps.add(rsps.GET, BankHolidays.source_url, json=BankHolidays.load_backup_data())
         return BankHolidays(**kwargs)
from datetime import datetime, time, timedelta
from collections import namedtuple

from govuk_bank_holidays.bank_holidays import BankHolidays
from notifications_utils.timezones import convert_utc_to_bst, utc_string_to_aware_gmt_datetime


LETTER_PROCESSING_DEADLINE = time(17, 30)
CANCELLABLE_JOB_LETTER_STATUSES = [
    'created', 'cancelled', 'virus-scan-failed', 'validation-failed', 'technical-failure', 'pending-virus-check'
]


non_working_days_dvla = BankHolidays(
    use_cached_holidays=True,
    weekend=(5, 6),
)
non_working_days_royal_mail = BankHolidays(
    use_cached_holidays=True,
    weekend=(6,)  # Only Sunday (day 6 of the week) is a non-working day
)


def set_gmt_hour(day, hour):
    return day.astimezone(pytz.timezone('Europe/London')).replace(hour=hour, minute=0).astimezone(pytz.utc)


def get_letter_timings(upload_time, postage='second'):

    LetterTimings = namedtuple(
        'LetterTimings',
Example #12
0
 def test_using_cached_list_of_holidays(self, mock_logger):
     with responses.RequestsMock():
         bank_holidays = BankHolidays(use_cached_holidays=True)
     mock_logger.warning.assert_not_called()
     self.assertTrue(bank_holidays.get_holidays())