From 5ebb89a6d587e9a25edb26fe09a8272cf66269dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 9 Mar 2023 19:56:06 +0800 Subject: [PATCH] Moved the month_end utility from the "accounting.report.period.period" module to the new "accounting.report.period.month_end" module. --- src/accounting/report/period/month_end.py | 31 +++++++++++++++++++++++ src/accounting/report/period/period.py | 12 +-------- src/accounting/report/period/periods.py | 3 ++- 3 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 src/accounting/report/period/month_end.py diff --git a/src/accounting/report/period/month_end.py b/src/accounting/report/period/month_end.py new file mode 100644 index 0000000..3efdcc2 --- /dev/null +++ b/src/accounting/report/period/month_end.py @@ -0,0 +1,31 @@ +# The Mia! Accounting Flask Project. +# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/4 + +# Copyright (c) 2023 imacat. +# +# 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. +"""The utility to return the end of a month. + +""" +import calendar +from datetime import date + + +def month_end(day: date) -> date: + """Returns the end day of month for a date. + + :param day: The date. + :return: The end day of the month of that day. + """ + last_day: int = calendar.monthrange(day.year, day.month)[1] + return date(day.year, day.month, last_day) diff --git a/src/accounting/report/period/period.py b/src/accounting/report/period/period.py index cd8a132..b86b6da 100644 --- a/src/accounting/report/period/period.py +++ b/src/accounting/report/period/period.py @@ -20,11 +20,11 @@ This file is largely taken from the NanoParma ERP project, first written in 2021/9/16 by imacat (imacat@nanoparma.com). """ -import calendar import typing as t from datetime import date, timedelta from .description import get_desc +from .month_end import month_end from .specification import get_spec @@ -127,13 +127,3 @@ class Period: if self.start is None: return None return Period(None, self.start - timedelta(days=1)) - - -def month_end(day: date) -> date: - """Returns the end day of month for a date. - - :param day: The date. - :return: The end day of the month of that day. - """ - last_day: int = calendar.monthrange(day.year, day.month)[1] - return date(day.year, day.month, last_day) diff --git a/src/accounting/report/period/periods.py b/src/accounting/report/period/periods.py index cca1ecf..3b8fd72 100644 --- a/src/accounting/report/period/periods.py +++ b/src/accounting/report/period/periods.py @@ -20,7 +20,8 @@ from datetime import date, timedelta from accounting.locale import gettext -from .period import Period, month_end +from .month_end import month_end +from .period import Period class ThisMonth(Period):