77import datetime
88from typing import Any
99from typing import Tuple
10- from typing import Union
1110
1211__all__ = [
1312 "natural_clock" ,
@@ -168,20 +167,18 @@ def _informal_time(value, hour):
168167 return clock
169168
170169
171- def natural_clock (
172- value : datetime .datetime , formal : bool = True
173- ) -> Union [str , datetime .datetime ]:
170+ def natural_clock (value : Any , formal : bool = True ) -> Any :
174171 """Returns human-readable time.
175172
176173 Compares time values to present time returns representing readable of time
177174 with the given day period.
178175
179176 Args:
180- value (datetime.datetime ): any datetime.
177+ value (Any ): any datetime.
181178 formal (bool): Formal or informal reading. Defaults to True.
182179
183180 Returns:
184- str : readable time.
181+ Any : readable time or original object .
185182 """
186183 try :
187184 time = datetime .time (value .hour , value .minute , value .second )
@@ -222,19 +219,17 @@ def abs_timedelta(delta: datetime.timedelta) -> datetime.timedelta:
222219 return delta
223220
224221
225- def date_and_delta (
226- value : Union [datetime .datetime , datetime .timedelta , int ]
227- ) -> Tuple [Any , Any ]:
222+ def date_and_delta (value : Any ) -> Tuple [Any , Any ]:
228223 """Returns date and timedelta.
229224
230225 Turn a value into a date and a timedelta which represents how long ago
231226 it was. If that's not possible, return (None, value).
232227
233228 Args:
234- value (Union[datetime.datetime, datetime.timedelta, int] ): date value.
229+ value (Any ): date value.
235230
236231 Returns:
237- [type ]: [description]
232+ Tuple[Any, Any ]: date and delta or tuple of None, original value.
238233 """
239234 now = _now ()
240235 if isinstance (value , datetime .datetime ):
@@ -297,13 +292,11 @@ def _one_year(days, months, use_months):
297292 return "1 ano e %d dias" % days
298293
299294
300- def more_than_one_year (years ) :
295+ def more_than_one_year (years : int ) -> str :
301296 return "%d anos" % years
302297
303298
304- def natural_delta (
305- value : datetime .datetime , use_months : bool = True
306- ) -> Union [str , datetime .datetime ]:
299+ def natural_delta (value : Any , use_months : bool = True ) -> Any :
307300 """Returns human-readable time difference.
308301
309302 Given a timedelta or a number of seconds, return a natural
@@ -313,11 +306,11 @@ def natural_delta(
313306 for fuzziness between years.
314307
315308 Args:
316- value (datetime.datetime ): date.
309+ value (Any ): date.
317310 use_months (bool): show the number of months. Defaults to True.
318311
319312 Returns:
320- str : time representation in natural language.
313+ Any : time representation in natural language or original object .
321314 """
322315 date , delta = date_and_delta (value )
323316 if date is None :
@@ -338,9 +331,7 @@ def natural_delta(
338331 return more_than_one_year (years )
339332
340333
341- def natural_time (
342- value : datetime .datetime , future : bool = False , use_months : bool = True
343- ) -> Union [str , datetime .datetime ]:
334+ def natural_time (value : Any , future : bool = False , use_months : bool = True ) -> Any :
344335 """Returns human-readable time.
345336
346337 Given a datetime or a number of seconds, return a natural representation
@@ -351,12 +342,12 @@ def natural_time(
351342 unless ``future`` is set to True.
352343
353344 Args:
354- value (datetime.datetime ): time value.
345+ value (Any ): time value.
355346 future (bool): if false uses past tense. Defaults to False.
356347 use_months (bool): if true return number of months. Defaults to True.
357348
358349 Returns:
359- Union[str, datetime.datetime] : time in natural language.
350+ Any : time in natural language or original object .
360351 """
361352 now = _now ()
362353 date , delta = date_and_delta (value )
@@ -375,21 +366,19 @@ def natural_time(
375366 return ago % delta
376367
377368
378- def natural_day (
379- value : Union [datetime .datetime , datetime .date ], has_year : bool = False
380- ) -> Union [str , datetime .datetime , datetime .date ]:
369+ def natural_day (value : Any , has_year : bool = False ) -> Any :
381370 """Returns human-readable day.
382371
383372 For date values that are tomorrow, today or yesterday compared to
384373 present day returns representing string. Otherwise, returns a string
385374 formatted according to ``format``.
386375
387376 Args:
388- value (Union[datetime.datetime, datetime.date] ): a date.
377+ value (Any ): a date.
389378 has_year (bool): if year is added. Defaults to False.
390379
391380 Returns:
392- Union[str, datetime.datetime] : date formatted in natural language.
381+ Any : date formatted in natural language or original object .
393382 """
394383 try :
395384 date = datetime .date (value .year , value .month , value .day )
0 commit comments