dately 1.0.9__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dately-2.0.0/PKG-INFO +60 -0
- dately-2.0.0/README.md +45 -0
- {dately-1.0.9 → dately-2.0.0}/dately/core.py +3 -4
- dately-2.0.0/dately/mskutils.py +77 -0
- dately-2.0.0/dately/sysutils.py +60 -0
- {dately-1.0.9 → dately-2.0.0}/dately/timeutils.py +8 -2
- dately-2.0.0/dately/timezone.py +653 -0
- {dately-1.0.9 → dately-2.0.0}/dately/utils.py +1 -31
- dately-2.0.0/dately.egg-info/PKG-INFO +60 -0
- {dately-1.0.9 → dately-2.0.0}/dately.egg-info/SOURCES.txt +2 -0
- {dately-1.0.9 → dately-2.0.0}/setup.py +1 -1
- dately-1.0.9/PKG-INFO +0 -56
- dately-1.0.9/README.md +0 -41
- dately-1.0.9/dately/timezone.py +0 -475
- dately-1.0.9/dately.egg-info/PKG-INFO +0 -56
- {dately-1.0.9 → dately-2.0.0}/dately/__init__.py +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately/mold/__init__.py +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately/mold/pyd/Compiled.cp38-win_amd64.pyd +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately/mold/pyd/__init__.py +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately/mold/pyd/cdatetime/UniversalDateFormatter.cp38-win_amd64.pyd +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately/mold/pyd/cdatetime/__init__.py +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately/mold/pyd/cdatetime/iso8601T.cp38-win_amd64.pyd +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately/mold/pyd/cdatetime/iso8601Z.cp38-win_amd64.pyd +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately/mold/pyd/cdatetime/whichformat.cp38-win_amd64.pyd +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately/mold/pyd/clean_str.cp38-win_amd64.pyd +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately/mold/pyd/time_zones.cp38-win_amd64.pyd +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately.egg-info/dependency_links.txt +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately.egg-info/requires.txt +0 -0
- {dately-1.0.9 → dately-2.0.0}/dately.egg-info/top_level.txt +0 -0
- {dately-1.0.9 → dately-2.0.0}/setup.cfg +0 -0
dately-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dately
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: A library for manipulating datetime strings.
|
|
5
|
+
Home-page: https://github.com/cedricmoorejr/dately
|
|
6
|
+
Author: Cedric Moore Jr.
|
|
7
|
+
Author-email: cedric@doydl.tech
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Source Code, https://github.com/cedricmoorejr/dately/tree/main/dately
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<img src="https://raw.githubusercontent.com/cedricmoorejr/dately/main/dately/assets/dately_logo.png" alt="Dately Logo" width="500"/>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Dately Library: Comprehensive Date and Time Handling in Python
|
|
22
|
+
|
|
23
|
+
The `dately` module is a comprehensive library designed for advanced date and time manipulation. It offers extensive capabilities to handle various date and time formats, ensuring compatibility across different systems and data structures. The module provides tools for validating, extracting, and transforming date and time information with a focus on performance and accuracy.
|
|
24
|
+
|
|
25
|
+
#### Why Choose Dately?
|
|
26
|
+
|
|
27
|
+
- **Windows Optimized**: Specifically addresses inconsistencies in Python's date formatting on the Windows operating system.
|
|
28
|
+
- **Comprehensive Functionalities**: Supports date parsing, detection, extraction, and conversion for various input types, including date strings, datetime objects, pandas Series, and NumPy arrays.
|
|
29
|
+
- **High Performance**: Leverages both high-level Python and low-level C code (via Cython) for efficient operations.
|
|
30
|
+
|
|
31
|
+
#### Key Features
|
|
32
|
+
|
|
33
|
+
1. **Date and Time Format Detection**:
|
|
34
|
+
- Automatically detect various date and time formats from strings, ensuring seamless parsing and conversion.
|
|
35
|
+
- Supports a wide range of date formats, including standard and unique custom formats.
|
|
36
|
+
|
|
37
|
+
2. **Timezone Management**:
|
|
38
|
+
- Provides detailed information for specific time zones.
|
|
39
|
+
- Converts time from one time zone to another.
|
|
40
|
+
- Retrieves the current time for specific time zones.
|
|
41
|
+
- Categorizes time zones by country, offset, and daylight saving time observance.
|
|
42
|
+
|
|
43
|
+
3. **String Manipulation and Validation**:
|
|
44
|
+
- Extract specific components (year, month, day, hour, minute, second, timezone) from datetime strings.
|
|
45
|
+
- Validate and replace parts of datetime strings to ensure accuracy and consistency.
|
|
46
|
+
- Strip time and timezone information from datetime strings when needed.
|
|
47
|
+
|
|
48
|
+
4. **Performance Optimizations**:
|
|
49
|
+
- Utilizes Cython to enhance performance for computationally intensive tasks.
|
|
50
|
+
- Interfaces with underlying C code to perform high-speed string operations and date validations.
|
|
51
|
+
|
|
52
|
+
#### Solving Windows Date Formatting Issues
|
|
53
|
+
|
|
54
|
+
A key aspect of this module is addressing inconsistencies in Python's date formatting on the Windows operating system. The module specifically targets the handling of the hyphen-minus (-) in date format specifiers. This flag, used to remove leading zeros from formatted output (e.g., turning '01' into '1' for January), works reliably on Unix-like systems but does not function as intended on Windows.
|
|
55
|
+
|
|
56
|
+
To solve this problem on Windows, the `dately` module introduces a workaround using regular expressions. It utilizes a detection function to determine the format string and then examines each date component for leading zeros through an extract_date_component function and a subsequent has_leading_zero check. Depending on the presence of leading zeros, the module adjusts the format string-replacing `%m` with `%-m` where applicable-to emulate the behavior expected from the hyphen-minus on Unix-like systems.
|
|
57
|
+
|
|
58
|
+
This method ensures that users on Windows achieve consistent date formatting, effectively compensating for the lack of native support for the hyphen-minus in date specifiers on this system.
|
|
59
|
+
|
|
60
|
+
Overall, `dately` is a powerful utility for anyone needing precise and flexible date and time handling in their applications, making it easier to manage, format, and validate date and time data consistently and efficiently.
|
dately-2.0.0/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/cedricmoorejr/dately/main/dately/assets/dately_logo.png" alt="Dately Logo" width="500"/>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Dately Library: Comprehensive Date and Time Handling in Python
|
|
7
|
+
|
|
8
|
+
The `dately` module is a comprehensive library designed for advanced date and time manipulation. It offers extensive capabilities to handle various date and time formats, ensuring compatibility across different systems and data structures. The module provides tools for validating, extracting, and transforming date and time information with a focus on performance and accuracy.
|
|
9
|
+
|
|
10
|
+
#### Why Choose Dately?
|
|
11
|
+
|
|
12
|
+
- **Windows Optimized**: Specifically addresses inconsistencies in Python's date formatting on the Windows operating system.
|
|
13
|
+
- **Comprehensive Functionalities**: Supports date parsing, detection, extraction, and conversion for various input types, including date strings, datetime objects, pandas Series, and NumPy arrays.
|
|
14
|
+
- **High Performance**: Leverages both high-level Python and low-level C code (via Cython) for efficient operations.
|
|
15
|
+
|
|
16
|
+
#### Key Features
|
|
17
|
+
|
|
18
|
+
1. **Date and Time Format Detection**:
|
|
19
|
+
- Automatically detect various date and time formats from strings, ensuring seamless parsing and conversion.
|
|
20
|
+
- Supports a wide range of date formats, including standard and unique custom formats.
|
|
21
|
+
|
|
22
|
+
2. **Timezone Management**:
|
|
23
|
+
- Provides detailed information for specific time zones.
|
|
24
|
+
- Converts time from one time zone to another.
|
|
25
|
+
- Retrieves the current time for specific time zones.
|
|
26
|
+
- Categorizes time zones by country, offset, and daylight saving time observance.
|
|
27
|
+
|
|
28
|
+
3. **String Manipulation and Validation**:
|
|
29
|
+
- Extract specific components (year, month, day, hour, minute, second, timezone) from datetime strings.
|
|
30
|
+
- Validate and replace parts of datetime strings to ensure accuracy and consistency.
|
|
31
|
+
- Strip time and timezone information from datetime strings when needed.
|
|
32
|
+
|
|
33
|
+
4. **Performance Optimizations**:
|
|
34
|
+
- Utilizes Cython to enhance performance for computationally intensive tasks.
|
|
35
|
+
- Interfaces with underlying C code to perform high-speed string operations and date validations.
|
|
36
|
+
|
|
37
|
+
#### Solving Windows Date Formatting Issues
|
|
38
|
+
|
|
39
|
+
A key aspect of this module is addressing inconsistencies in Python's date formatting on the Windows operating system. The module specifically targets the handling of the hyphen-minus (-) in date format specifiers. This flag, used to remove leading zeros from formatted output (e.g., turning '01' into '1' for January), works reliably on Unix-like systems but does not function as intended on Windows.
|
|
40
|
+
|
|
41
|
+
To solve this problem on Windows, the `dately` module introduces a workaround using regular expressions. It utilizes a detection function to determine the format string and then examines each date component for leading zeros through an extract_date_component function and a subsequent has_leading_zero check. Depending on the presence of leading zeros, the module adjusts the format string-replacing `%m` with `%-m` where applicable-to emulate the behavior expected from the hyphen-minus on Unix-like systems.
|
|
42
|
+
|
|
43
|
+
This method ensures that users on Windows achieve consistent date formatting, effectively compensating for the lack of native support for the hyphen-minus in date specifiers on this system.
|
|
44
|
+
|
|
45
|
+
Overall, `dately` is a powerful utility for anyone needing precise and flexible date and time handling in their applications, making it easier to manage, format, and validate date and time data consistently and efficiently.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import threading
|
|
2
2
|
|
|
3
3
|
def import_specific_parts():
|
|
4
|
-
global
|
|
5
|
-
from .timezone import
|
|
4
|
+
global TimeZoner
|
|
5
|
+
from .timezone import TimeZoner
|
|
6
6
|
|
|
7
7
|
thread = threading.Thread(target=import_specific_parts)
|
|
8
8
|
thread.start()
|
|
@@ -12,7 +12,6 @@ import numpy as np
|
|
|
12
12
|
import pandas as pd
|
|
13
13
|
from copy import deepcopy
|
|
14
14
|
|
|
15
|
-
# Import all functions and classes from custom utility modules using relative imports
|
|
16
15
|
from .mold.pyd.cdatetime.whichformat import *
|
|
17
16
|
from .utils import *
|
|
18
17
|
from .timeutils import *
|
|
@@ -505,5 +504,5 @@ dt = DatelyDate()
|
|
|
505
504
|
# Define public interface
|
|
506
505
|
__all__ = [
|
|
507
506
|
"dt",
|
|
508
|
-
"
|
|
507
|
+
"TimeZoner"
|
|
509
508
|
]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
# Define public interface
|
|
5
|
+
__all__ = ['Shift']
|
|
6
|
+
|
|
7
|
+
class Shift:
|
|
8
|
+
class bool:
|
|
9
|
+
@staticmethod
|
|
10
|
+
def bytes(s):
|
|
11
|
+
""" base64 """
|
|
12
|
+
if len(s) % 4 != 0:
|
|
13
|
+
return False
|
|
14
|
+
if not re.match(r'^[A-Za-z0-9+/]*={0,2}$', s):
|
|
15
|
+
return False
|
|
16
|
+
try:
|
|
17
|
+
decoded_bytes = base64.b64decode(s, validate=True)
|
|
18
|
+
decoded_str = decoded_bytes.decode('utf-8')
|
|
19
|
+
return True
|
|
20
|
+
except (base64.binascii.Error, UnicodeDecodeError):
|
|
21
|
+
return False
|
|
22
|
+
@staticmethod
|
|
23
|
+
def bin(s):
|
|
24
|
+
""" Binary """
|
|
25
|
+
if not all(c in '01' for c in s):
|
|
26
|
+
return False
|
|
27
|
+
if len(s) % 8 != 0:
|
|
28
|
+
return False
|
|
29
|
+
try:
|
|
30
|
+
bytes_list = [s[i:i+8] for i in range(0, len(s), 8)]
|
|
31
|
+
decoded_chars = [chr(int(byte, 2)) for byte in bytes_list]
|
|
32
|
+
decoded_str = ''.join(decoded_chars)
|
|
33
|
+
return True
|
|
34
|
+
except ValueError:
|
|
35
|
+
return False
|
|
36
|
+
|
|
37
|
+
class format:
|
|
38
|
+
@staticmethod
|
|
39
|
+
def chr(data, call):
|
|
40
|
+
""" base64 """
|
|
41
|
+
if call == "unformat":
|
|
42
|
+
if not Shift.bool.bytes(data):
|
|
43
|
+
return base64.b64encode(data.encode('utf-8')).decode('utf-8')
|
|
44
|
+
elif call == "format":
|
|
45
|
+
if Shift.bool.bytes(data):
|
|
46
|
+
try:
|
|
47
|
+
return base64.b64decode(data).decode('utf-8')
|
|
48
|
+
except (base64.binascii.Error, UnicodeDecodeError):
|
|
49
|
+
raise ValueError("Invalid base64 input.")
|
|
50
|
+
else:
|
|
51
|
+
raise ValueError("Invalid call. Use 'unformat' or 'format'.")
|
|
52
|
+
@staticmethod
|
|
53
|
+
def str(data, call):
|
|
54
|
+
""" Binary """
|
|
55
|
+
if call == "unformat":
|
|
56
|
+
if not Shift.bool.bin(data):
|
|
57
|
+
return ''.join(format(ord(char), '08b') for char in data)
|
|
58
|
+
elif call == "format":
|
|
59
|
+
if Shift.bool.bin(data):
|
|
60
|
+
try:
|
|
61
|
+
chars = [chr(int(data[i:i+8], 2)) for i in range(0, len(data), 8)]
|
|
62
|
+
return ''.join(chars)
|
|
63
|
+
except ValueError:
|
|
64
|
+
raise ValueError("Invalid binary input.")
|
|
65
|
+
else:
|
|
66
|
+
raise ValueError("Invalid call. Use 'unformat' or 'format'.")
|
|
67
|
+
|
|
68
|
+
class type:
|
|
69
|
+
@staticmethod
|
|
70
|
+
def map(s, add, ret=False):
|
|
71
|
+
formatted = Shift.format.chr(s, "format")
|
|
72
|
+
str_formatted = f'{formatted}{add}'
|
|
73
|
+
unformatted = Shift.format.chr(str_formatted, "unformat")
|
|
74
|
+
if ret:
|
|
75
|
+
return Shift.format.chr(unformatted, "format")
|
|
76
|
+
return unformatted
|
|
77
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
# Define public interface
|
|
4
|
+
__all__ = ['UnixTime']
|
|
5
|
+
|
|
6
|
+
class UnixTime:
|
|
7
|
+
@staticmethod
|
|
8
|
+
def Timestamp(year=None, month=None, day=None, hour=None, minute=None, second=None, weekday=None, yearday=None, isdst=-1):
|
|
9
|
+
"""
|
|
10
|
+
Initializes the UnixTime with specific time components or defaults to current time values.
|
|
11
|
+
|
|
12
|
+
Parameters:
|
|
13
|
+
year (int): The year (e.g., 2021). Default is the current year if not provided or invalid.
|
|
14
|
+
month (int): The month (1-12). Default is the current month if not provided or invalid.
|
|
15
|
+
day (int): The day of the month (1-31). Default is the current day if not provided or invalid.
|
|
16
|
+
hour (int): The hour (0-23). Default is the current hour if not provided or invalid.
|
|
17
|
+
minute (int): The minute (0-59). Default is the current minute if not provided or invalid.
|
|
18
|
+
second (int): The second (0-59). Default is the current second if not provided or invalid.
|
|
19
|
+
weekday (int): The day of the week (0-6, Monday is 0). Default is 0.
|
|
20
|
+
yearday (int): The day of the year (1-366). Default is 0.
|
|
21
|
+
isdst (int): Daylight Saving Time flag. Use -1 for automatic DST detection. Default is -1.
|
|
22
|
+
"""
|
|
23
|
+
current_time = time.localtime()
|
|
24
|
+
|
|
25
|
+
year = UnixTime.validate_input(year, current_time.tm_year)
|
|
26
|
+
month = UnixTime.validate_input(month, current_time.tm_mon)
|
|
27
|
+
day = UnixTime.validate_input(day, current_time.tm_mday)
|
|
28
|
+
hour = UnixTime.validate_input(hour, current_time.tm_hour)
|
|
29
|
+
minute = UnixTime.validate_input(minute, current_time.tm_min)
|
|
30
|
+
second = UnixTime.validate_input(second, current_time.tm_sec)
|
|
31
|
+
weekday = UnixTime.validate_input(weekday, 0)
|
|
32
|
+
yearday = UnixTime.validate_input(yearday, 0)
|
|
33
|
+
isdst = UnixTime.validate_input(isdst, -1)
|
|
34
|
+
|
|
35
|
+
time_tuple = (year, month, day, hour, minute, second, weekday, yearday, isdst)
|
|
36
|
+
return int(time.mktime(time_tuple))
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def Date(unix_timestamp):
|
|
40
|
+
"""
|
|
41
|
+
Converts a Unix timestamp to a human-readable date.
|
|
42
|
+
|
|
43
|
+
Parameters:
|
|
44
|
+
unix_timestamp (int): The Unix timestamp to convert.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
str: The human-readable date in the format 'YYYY-MM-DD HH:MM:SS'.
|
|
48
|
+
"""
|
|
49
|
+
time_struct = time.localtime(unix_timestamp)
|
|
50
|
+
return time.strftime('%Y-%m-%d %H:%M:%S', time_struct)
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
def validate_input(value, default):
|
|
54
|
+
"""
|
|
55
|
+
Validates the input to ensure it is an integer or defaults if None or invalid.
|
|
56
|
+
"""
|
|
57
|
+
try:
|
|
58
|
+
return int(value) if value is not None else default
|
|
59
|
+
except (TypeError, ValueError):
|
|
60
|
+
return default
|
|
@@ -4,8 +4,14 @@ import time
|
|
|
4
4
|
|
|
5
5
|
# Import all functions and classes from custom utility modules
|
|
6
6
|
from .utils import *
|
|
7
|
-
from .mold.pyd.Compiled import
|
|
8
|
-
|
|
7
|
+
from .mold.pyd.Compiled import (
|
|
8
|
+
datetime_regex as datetime_pattern_search,
|
|
9
|
+
anytime_regex,
|
|
10
|
+
timemeridiem_regex,
|
|
11
|
+
timeboundary_regex,
|
|
12
|
+
time_only_regex,
|
|
13
|
+
get_time_fragment as gtf,
|
|
14
|
+
)
|
|
9
15
|
|
|
10
16
|
|
|
11
17
|
# Define public interface
|