# !/usr/bin/python3
# coding: utf-8

# Copyright 2016-2018 Stefano Fogarollo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


""" Datetime utils """

import datetime
from enum import Enum


class Weekday(Enum):
    """ Representing weekday by using ints (datetime standard) """

    MONDAY = 0
    TUESDAY = 1
    WEDNESDAY = 2
    THURSDAY = 3
    FRIDAY = 4
    SATURDAY = 5
    SUNDAY = 6


def get_next_weekday(weekday):
    """
    :param weekday: Weekday
        Weekday to get
    :return: datetime
        Date of next monday, tuesday ...
    """

    now = datetime.datetime.now()
    if now.weekday() == weekday:
        return now + datetime.timedelta(days=7)

    t = datetime.timedelta(
        (7 + weekday.value - now.weekday()) % 7
    )  # time delta to next instance
    return now + t

@@ -882,16 +882,290 @@
 Y = 6%0A%0A%0A
+def get_just_date(date):%0A    %22%22%22%0A    :param date: datetime%0A        Date with possible hours%0A    :return: date%0A        Just day, month and year (setting hours to 00:00:00)%0A    %22%22%22%0A%0A    return datetime.datetime(%0A        date.year,%0A        date.month,%0A        date.day%0A    )%0A%0A%0A
 def get_
@@ -1383,16 +1383,22 @@
  weekday
+.value
 :%0A      
@@ -1399,28 +1399,23 @@
         
-return now +
+delta =
  datetim
@@ -1438,14 +1438,31 @@
 =7)%0A
-%0A    t
+    else:%0A        delta
  = d
@@ -1488,16 +1488,20 @@
         
+   
+ 
 (7 + wee
@@ -1532,16 +1532,20 @@
 ()) %25 7%0A
+    
     )  #
@@ -1588,12 +1588,476 @@
 urn 
-now + t
+get_just_date(now + delta)%0A%0A%0Adef get_last_weekday(weekday):%0A    %22%22%22%0A    :param weekday: Weekday%0A        Weekday to get%0A    :return: datetime%0A        Date of next monday, tuesday ...%0A    %22%22%22%0A%0A    now = datetime.datetime.now()%0A    if now.weekday() == weekday.value:%0A        delta = - datetime.timedelta(days=7)%0A    else:%0A        delta = datetime.timedelta(%0A            - now.weekday() + weekday.value%0A        )  # time D to last sunday%0A    return get_just_date(now + delta)
 %0A

add get last weekday