Skip to content

Commit

Permalink
refactor: java.util.Date
Browse files Browse the repository at this point in the history
inherit from datetime.datetime
  • Loading branch information
cesarcoatl committed Jun 4, 2021
1 parent 6be116c commit 370503c
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 78 deletions.
4 changes: 3 additions & 1 deletion src/java/util/__init__.py
Expand Up @@ -10,10 +10,12 @@

__all__ = ["Date", "EventObject", "Locale"]

from datetime import datetime

from java.lang import Object


class Date(Object):
class Date(datetime):
"""The class Date represents a specific instant in time, with
millisecond precision.
"""
Expand Down
5 changes: 3 additions & 2 deletions src/system/alarm.py
Expand Up @@ -27,6 +27,7 @@

import system.date
from java.lang import Object
from java.util import Date


class AlarmQueryResults(ABCMeta):
Expand Down Expand Up @@ -205,10 +206,10 @@ def queryJournal(
EventState, Priority, IsSystemEvent.
Args:
startDate (datetime): The start of the time range to query.
startDate (Date): The start of the time range to query.
Defaults to 8 hours previous to now if omitted. Time range
is inclusive.
endDate (datetime): The end of the time range to query. Defaults
endDate (Date): The end of the time range to query. Defaults
to "now" if omitted.
journalName (str): The journal name to query.
priority (list[str]): A list of possible priorities to match.
Expand Down
100 changes: 50 additions & 50 deletions src/system/date.py
Expand Up @@ -55,14 +55,14 @@

from datetime import datetime, timedelta

from java.util import Locale
from java.util import Date, Locale


def addDays(date, value):
"""Add or subtract an amount of days to a given date and time.
Args:
date (datetime): The starting date.
date (Date): The starting date.
value (int): The number of units to add, or subtract if the
value is negative.
Expand All @@ -77,7 +77,7 @@ def addHours(date, value):
"""Add or subtract an amount of hours to a given date and time.
Args:
date (datetime): The starting date.
date (Date): The starting date.
value (int): The number of units to add, or subtract if the
value is negative.
Expand All @@ -93,7 +93,7 @@ def addMillis(date, value):
time.
Args:
date (datetime): The starting date.
date (Date): The starting date.
value (int): The number of units to add, or subtract if the
value is negative.
Expand All @@ -108,7 +108,7 @@ def addMinutes(date, value):
"""Add or subtract an amount of minutes to a given date and time.
Args:
date (datetime): The starting date.
date (Date): The starting date.
value (int): The number of units to add, or subtract if the
value is negative.
Expand All @@ -129,7 +129,7 @@ def addMonths(date, value):
available day, in this case April 30th.
Args:
date (datetime): The starting date.
date (Date): The starting date.
value (int): The number of units to add, or subtract if the
value is negative.
Expand All @@ -151,7 +151,7 @@ def addSeconds(date, value):
"""Add or subtract an amount of seconds to a given date and time.
Args:
date (datetime): The starting date.
date (Date): The starting date.
value (int): The number of units to add, or subtract if the
value is negative.
Expand All @@ -166,7 +166,7 @@ def addWeeks(date, value):
"""Add or subtract an amount of weeks to a given date and time.
Args:
date (datetime): The starting date.
date (Date): The starting date.
value (int): The number of units to add, or subtract if the
value is negative.
Expand All @@ -181,7 +181,7 @@ def addYears(date, value):
"""Add or subtract an amount of years to a given date and time.
Args:
date (datetime): The starting date.
date (Date): The starting date.
value (int): The number of units to add, or subtract if the
value is negative.
Expand All @@ -198,8 +198,8 @@ def daysBetween(date_1, date_2):
Daylight Saving Time changes are taken into account.
Args:
date_1 (datetime): The first date to use.
date_2 (datetime): The second date to use.
date_1 (Date): The first date to use.
date_2 (Date): The second date to use.
Returns:
int: An integer that is representative of the difference between
Expand All @@ -217,7 +217,7 @@ def format(date, format="yyyy-MM-dd HH:mm:ss"):
directive on strftime().
Args:
date (datetime): The date to format.
date (Date): The date to format.
format (str): A format string such as "yyyy-MM-dd HH:mm:ss".
Optional.
Expand Down Expand Up @@ -264,7 +264,7 @@ def getAMorPM(date):
after noon.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand Down Expand Up @@ -295,7 +295,7 @@ def getDayOfMonth(date):
month is day 1.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -309,7 +309,7 @@ def getDayOfWeek(date):
Sunday is day 1, Saturday is day 7.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -323,7 +323,7 @@ def getDayOfYear(date):
year is day 1.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -336,7 +336,7 @@ def getHour12(date):
midnight are returned as 0.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -349,7 +349,7 @@ def getHour24(date):
is zero.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -361,7 +361,7 @@ def getMillis(date):
"""Extracts the milliseconds from a date, ranging from 0-999.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -373,7 +373,7 @@ def getMinute(date):
"""Extracts the minutes from a date, ranging from 0-59.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -385,7 +385,7 @@ def getMonth(date):
"""Extracts the month from a date, where January is month 0.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -397,7 +397,7 @@ def getQuarter(date):
"""Extracts the quarter from a date, ranging from 1-4.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -409,7 +409,7 @@ def getSecond(date):
"""Extracts the seconds from a date, ranging from 0-59.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -431,7 +431,7 @@ def getTimezoneOffset(date=datetime.now()):
instant, taking Daylight Saving Time into account.
Args:
date (datetime): The instant in time for which to calculate the
date (Date): The instant in time for which to calculate the
offset. Uses now() if omitted. Optional.
Returns:
Expand All @@ -455,7 +455,7 @@ def getYear(date):
"""Extracts the year from a date.
Args:
date (datetime): The date to use.
date (Date): The date to use.
Returns:
int: An integer that is representative of the extracted value.
Expand All @@ -467,8 +467,8 @@ def hoursBetween(date_1, date_2):
"""Calculates the number of whole hours between two dates.
Args:
date_1 (datetime): The first date to use.
date_2 (datetime): The second date to use.
date_1 (Date): The first date to use.
date_2 (Date): The second date to use.
Returns:
int: An integer that is representative of the difference between
Expand All @@ -483,8 +483,8 @@ def isAfter(date_1, date_2):
"""Compares two dates to see if date_1 is after date_2.
Args:
date_1 (datetime): The first date.
date_2 (datetime): The second date.
date_1 (Date): The first date.
date_2 (Date): The second date.
Returns:
bool: True (1) if date_1 is after date_2, False (0) otherwise.
Expand All @@ -496,8 +496,8 @@ def isBefore(date_1, date_2):
"""Compares to dates to see if date_1 is before date_2.
Args:
date_1 (datetime): The first date.
date_2 (datetime): The second date.
date_1 (Date): The first date.
date_2 (Date): The second date.
Returns:
bool: True (1) if date_1 is before date_2, False (0) otherwise.
Expand All @@ -510,9 +510,9 @@ def isBetween(target_date, start_date, end_date):
dates.
Args:
target_date (datetime): The date to compare.
start_date (datetime): The start of a date range.
end_date (datetime): The end of a date range. This date must be
target_date (Date): The date to compare.
start_date (Date): The start of a date range.
end_date (Date): The end of a date range. This date must be
after the start date.
Returns:
Expand All @@ -527,7 +527,7 @@ def isDaylightTime(date=datetime.now()):
Time during the date specified.
Args:
date (datetime): The date you want to check if the current
date (Date): The date you want to check if the current
timezone is observing Daylight Saving Time. Uses now() if
omitted. Optional.
Expand Down Expand Up @@ -558,7 +558,7 @@ def midnight(date):
millisecond fields set to zero.
Args:
date (datetime): The starting date.
date (Date): The starting date.
Returns:
datetime: A new date, set to midnight of the day provided.
Expand All @@ -570,8 +570,8 @@ def millisBetween(date_1, date_2):
"""Calculates the number of whole milliseconds between two dates.
Args:
date_1 (datetime): The first date to use.
date_2 (datetime): The second date to use.
date_1 (Date): The first date to use.
date_2 (Date): The second date to use.
Returns:
long: An integer that is representative of the difference
Expand All @@ -586,8 +586,8 @@ def minutesBetween(date_1, date_2):
"""Calculates the number of whole minutes between two dates.
Args:
date_1 (datetime): The first date to use.
date_2 (datetime): The second date to use.
date_1 (Date): The first date to use.
date_2 (Date): The second date to use.
Returns:
int: An integer that is representative of the difference between
Expand All @@ -603,8 +603,8 @@ def monthsBetween(date_1, date_2):
Saving Time changes are taken into account.
Args:
date_1 (datetime): The first date to use.
date_2 (datetime): The second date to use.
date_1 (Date): The first date to use.
date_2 (Date): The second date to use.
Returns:
int: An integer that is representative of the difference between
Expand Down Expand Up @@ -659,8 +659,8 @@ def secondsBetween(date_1, date_2):
"""Calculates the number of whole seconds between two dates.
Args:
date_1 (datetime): The first date to use.
date_2 (datetime): The second date to use.
date_1 (Date): The first date to use.
date_2 (Date): The second date to use.
Returns:
int: An integer that is representative of the difference between
Expand All @@ -676,7 +676,7 @@ def setTime(date, hour, minute, second):
set as specified.
Args:
date (datetime): The starting date.
date (Date): The starting date.
hour (int): The hours (0-23) to set.
minute(int): The minutes (0-59) to set.
second (int): The seconds (0-59) to set.
Expand All @@ -692,7 +692,7 @@ def toMillis(date):
January 1, 1970, 00:00:00 UTC (GMT).
Args:
date (datetime): The date object to convert.
date (Date): The date object to convert.
Returns:
int: 8-byte integer representing the number of millisecond
Expand All @@ -708,8 +708,8 @@ def weeksBetween(date_1, date_2):
"""Calculates the number of whole weeks between two dates.
Args:
date_1 (datetime): The first date to use.
date_2 (datetime): The second date to use.
date_1 (Date): The first date to use.
date_2 (Date): The second date to use.
Returns:
int: An integer that is representative of the difference between
Expand All @@ -724,8 +724,8 @@ def yearsBetween(date_1, date_2):
Saving Time changes are taken into account.
Args:
date_1 (datetime): The first date to use.
date_2 (datetime): The second date to use.
date_1 (Date): The first date to use.
date_2 (Date): The second date to use.
Returns:
int: An integer that is representative of the difference between
Expand Down

0 comments on commit 370503c

Please sign in to comment.