Exemplo n.º 1
0
 def _replace_nd(g):
     delta = ddate(date.year, date.month, date.day) - \
         ddate(now.year, now.month, now.day)
     if delta.days == 0:
         return _(r'\T\o\d\a\y')
     elif delta.days == 1:
         return _(r'\T\o\m\o\r\r\o\w')
     elif delta.days == -1:
         return _(r'\Y\e\s\t\e\r\d\a\y')
     else:
         return g.group(1)
Exemplo n.º 2
0
 def post(self,request,month,day):
     obj = Record(date=ddate(ddate.today().year,month,day),user=request.user)
     bound_form = RecordForm(request.POST,instance = obj)
     if bound_form.is_valid():
         bound_form.save()
         return render(request,'journal/journal_timetable.html',context = get_journal_timetable_dictionary(month,day,request.user))
     else:
         return render(request,'journal/journal_add_record.html',context={'form':bound_form,'month':month,'day':day})
Exemplo n.º 3
0
    def get_finish_date_and_days(self, project=None):
        """Calculate and return the finish date and finish days."""
        # if no project is given, return 1987-15-10
        if not check_objects.is_project(project) or self._date is None:
            return ddate(1987, 10, 15), 0

        # get time needed for this offer
        time = self.get_time_total()

        # get initial date
        date = self._date

        # initialize finish days output
        days = 0

        # get first workday
        while date.weekday() not in project.get_work_days():
            days += 1
            date += timedelta(days=1)

        # add minimum_days
        min_days = project.get_minimum_days()
        while min_days > 0:
            # add the day only, if it is a working day
            if date.weekday() in project.get_work_days():
                min_days -= 1

            # add a day
            days += 1
            date += timedelta(days=1)

        # subtract hours_per_day from time on work_days, till time <= 0
        while time > 0:
            # t's a work day so subtract hours_per_day from time
            if date.weekday() in project.get_work_days():
                time -= project.get_hours_per_day()

            # add a day
            days += 1
            date += timedelta(days=1)

        return date, days
 def __init__(self, dateurl):
     Bookmark.count += 1
     self.dateurl = dateurl
     self._date_ = self.dateurl[-8:]
     self.date = ddate(int(self._date_[:4]), int(self._date_[4:6]),
                       int(self._date_[6:8]))
Exemplo n.º 5
0
from datetime import date as ddate
from datetime import timedelta as timedelta


n = input().split()
a = ddate(int(n[0]), int(n[1]), int(n[2]))
b = timedelta(int(input()))
c = a + b

print(c.year, c.month, c.day)
Exemplo n.º 6
0
    def get(self):
        args = self.parser.parse_args()
        if args.get('summary'):
            logs = RequestLog.query.order_by(RequestLog.created).all()

            if len(logs) < 1:
                return {}

            first_d = logs[0].created.date()
            last_d = logs[-1].created.date()

            result = OrderedDict()

            t_date = ddate(first_d.year, first_d.month, first_d.day)
            while t_date != last_d:
                result[str(t_date)] = 0
                t_date += timedelta(days=1)

            for log in logs:
                date = log.created.date()
                sdate = str(date)
                if result.get(sdate):
                    result[sdate] += 1
                else:
                    result[sdate] = 1

            if args.get('csv'):
                csv_tmp = tempfile.NamedTemporaryFile(mode='w+',
                                                      prefix='logs_csv_',
                                                      delete=False)
                csv_writer = csv.writer(csv_tmp)
                csv_writer.writerow(['DATE', 'N_REQUESTS'])

                for k, v in result.items():
                    csv_writer.writerow([k, v])

                csv_tmp.close()

                tmp_send = BytesIO()
                with open(csv_tmp.name, mode='rb') as f:
                    tmp_send.write(f.read())

                tmp_send.seek(0)
                response = send_file(tmp_send,
                                     mimetype='text/csv',
                                     as_attachment=True,
                                     attachment_filename='logs.csv')

                os.remove(csv_tmp.name)
                return response

            else:
                return result

        else:
            startdate = datetime.today().date() - timedelta(days=7)
            logs = RequestLog.query.filter(
                RequestLog.created > startdate).all()
            result = []

            for log in logs:
                result.append({
                    "client_id":
                    clientserializer.dumps(log.client_id),
                    "test_id":
                    testserializer.dumps(log.test_id),
                    "result":
                    log.result,
                    "error":
                    log.error,
                    "timestamp":
                    log.created.isoformat()
                })

            return {"results": result, "startdate": startdate.isoformat()}
Exemplo n.º 7
0
 def get_due_date(self):
     """Get due_date."""
     if self._date is not None:
         return self._date + timedelta(days=self._due_days)
     else:
         return ddate(1987, 10, 15)
Exemplo n.º 8
0
 def get(self,request,month,day):
     obj = Record(date=ddate(ddate.today().year,month,day),user=request.user)
     form = RecordForm(instance = obj)
     return render(request,'journal/journal_add_record.html',context={'form':form,'month':month,'day':day})
Exemplo n.º 9
0
def date_to_yearday(date: tuple) -> int:
    return ddate(*date).timetuple().tm_yday