11# The Mia! Accounting Project.
22# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/4
33
4- # Copyright (c) 2023 imacat.
4+ # Copyright (c) 2023-2024 imacat.
55#
66# Licensed under the Apache License, Version 2.0 (the "License");
77# you may not use this file except in compliance with the License.
2020import datetime as dt
2121
2222from accounting .locale import gettext
23+ from accounting .utils .timezone import get_tz_today
2324from .month_end import month_end
2425from .period import Period
2526
2627
2728class ThisMonth (Period ):
2829 """The period of this month."""
2930 def __init__ (self ):
30- today : dt .date = dt . date . today ()
31+ today : dt .date = get_tz_today ()
3132 this_month_start : dt .date = dt .date (today .year , today .month , 1 )
3233 super ().__init__ (this_month_start , month_end (today ))
3334 self .is_default = True
@@ -43,7 +44,7 @@ def _set_properties(self) -> None:
4344class LastMonth (Period ):
4445 """The period of this month."""
4546 def __init__ (self ):
46- today : dt .date = dt . date . today ()
47+ today : dt .date = get_tz_today ()
4748 year : int = today .year
4849 month : int = today .month - 1
4950 if month < 1 :
@@ -63,7 +64,7 @@ def _set_properties(self) -> None:
6364class SinceLastMonth (Period ):
6465 """The period of this month."""
6566 def __init__ (self ):
66- today : dt .date = dt . date . today ()
67+ today : dt .date = get_tz_today ()
6768 year : int = today .year
6869 month : int = today .month - 1
6970 if month < 1 :
@@ -82,7 +83,7 @@ def _set_properties(self) -> None:
8283class ThisYear (Period ):
8384 """The period of this year."""
8485 def __init__ (self ):
85- year : int = dt . date . today ().year
86+ year : int = get_tz_today ().year
8687 start : dt .date = dt .date (year , 1 , 1 )
8788 end : dt .date = dt .date (year , 12 , 31 )
8889 super ().__init__ (start , end )
@@ -97,7 +98,7 @@ def _set_properties(self) -> None:
9798class LastYear (Period ):
9899 """The period of last year."""
99100 def __init__ (self ):
100- year : int = dt . date . today ().year
101+ year : int = get_tz_today ().year
101102 start : dt .date = dt .date (year - 1 , 1 , 1 )
102103 end : dt .date = dt .date (year - 1 , 12 , 31 )
103104 super ().__init__ (start , end )
@@ -112,7 +113,7 @@ def _set_properties(self) -> None:
112113class Today (Period ):
113114 """The period of today."""
114115 def __init__ (self ):
115- today : dt .date = dt . date . today ()
116+ today : dt .date = get_tz_today ()
116117 super ().__init__ (today , today )
117118 self .is_today = True
118119
@@ -125,7 +126,7 @@ def _set_properties(self) -> None:
125126class Yesterday (Period ):
126127 """The period of yesterday."""
127128 def __init__ (self ):
128- yesterday : dt .date = dt . date . today () - dt .timedelta (days = 1 )
129+ yesterday : dt .date = get_tz_today () - dt .timedelta (days = 1 )
129130 super ().__init__ (yesterday , yesterday )
130131 self .is_yesterday = True
131132
0 commit comments