dately 2.1.2__tar.gz → 2.1.3__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.1.3/PKG-INFO +465 -0
- dately-2.1.3/README.md +450 -0
- dately-2.1.3/dately.egg-info/PKG-INFO +465 -0
- {dately-2.1.2 → dately-2.1.3}/setup.py +1 -1
- dately-2.1.2/PKG-INFO +0 -60
- dately-2.1.2/README.md +0 -45
- dately-2.1.2/dately.egg-info/PKG-INFO +0 -60
- {dately-2.1.2 → dately-2.1.3}/dately/__init__.py +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/core.py +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mold/__init__.py +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mold/pyd/Compiled.cp38-win_amd64.pyd +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mold/pyd/__init__.py +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mold/pyd/cdatetime/UniversalDateFormatter.cp38-win_amd64.pyd +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mold/pyd/cdatetime/__init__.py +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mold/pyd/cdatetime/iso8601T.cp38-win_amd64.pyd +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mold/pyd/cdatetime/iso8601Z.cp38-win_amd64.pyd +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mold/pyd/cdatetime/whichformat.cp38-win_amd64.pyd +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mold/pyd/clean_str.cp38-win_amd64.pyd +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mold/pyd/time_zones.cp38-win_amd64.pyd +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/mskutils.py +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/sysutils.py +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/timeutils.py +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/timezone.py +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately/utils.py +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately.egg-info/SOURCES.txt +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately.egg-info/dependency_links.txt +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately.egg-info/requires.txt +0 -0
- {dately-2.1.2 → dately-2.1.3}/dately.egg-info/top_level.txt +0 -0
- {dately-2.1.2 → dately-2.1.3}/setup.cfg +0 -0
dately-2.1.3/PKG-INFO
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dately
|
|
3
|
+
Version: 2.1.3
|
|
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
|
+
### Dately Library: Comprehensive Date and Time Handling in Python
|
|
21
|
+
|
|
22
|
+
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.
|
|
23
|
+
|
|
24
|
+
#### Table of Contents
|
|
25
|
+
1. [Why Choose Dately?](#why-choose-dately)
|
|
26
|
+
2. [Key Features](#key-features)
|
|
27
|
+
3. [Solving Windows Date Formatting Issues](#solving-windows-date-formatting-issues)
|
|
28
|
+
4. [Usage Examples - Working with Date Strings](#usage-examples---working-with-date-strings)
|
|
29
|
+
- [Importing the Module](#importing-the-module)
|
|
30
|
+
- [Extracting Datetime Components](#extracting-datetime-components)
|
|
31
|
+
- [Detecting Datetime Formats](#detecting-datetime-formats)
|
|
32
|
+
- [Converting Dates](#converting-dates)
|
|
33
|
+
- [Converting Dates in Dictionaries](#converting-dates-in-dictionaries)
|
|
34
|
+
- [Replacing Datestring](#replacing-datestring)
|
|
35
|
+
- [Replacing Datetimestring](#replacing-datetimestring)
|
|
36
|
+
5. [Working with Time Zones](#working-with-time-zones)
|
|
37
|
+
- [Retrieving Time Zone Information](#retrieving-time-zone-information)
|
|
38
|
+
- [Time Zone Operations](#time-zone-operations)
|
|
39
|
+
|
|
40
|
+
#### Why Choose Dately?
|
|
41
|
+
|
|
42
|
+
- **Windows Optimized**: Specifically addresses inconsistencies in Python's date formatting on the Windows operating system.
|
|
43
|
+
- **Comprehensive Functionalities**: Supports date parsing, detection, extraction, and conversion for various input types, including date strings, datetime objects, pandas Series, and NumPy arrays.
|
|
44
|
+
- **High Performance**: Leverages both high-level Python and low-level C code (via Cython) for efficient operations.
|
|
45
|
+
|
|
46
|
+
#### Key Features
|
|
47
|
+
|
|
48
|
+
1. **Date and Time Format Detection**:
|
|
49
|
+
- Automatically detect various date and time formats from strings, ensuring seamless parsing and conversion.
|
|
50
|
+
- Supports a wide range of date formats, including standard and unique custom formats.
|
|
51
|
+
|
|
52
|
+
2. **Timezone Management**:
|
|
53
|
+
- Provides detailed information for specific time zones.
|
|
54
|
+
- Converts time from one time zone to another.
|
|
55
|
+
- Retrieves the current time for specific time zones.
|
|
56
|
+
- Categorizes time zones by country, offset, and daylight saving time observance.
|
|
57
|
+
|
|
58
|
+
3. **String Manipulation and Validation**:
|
|
59
|
+
- Extract specific components (year, month, day, hour, minute, second, timezone) from datetime strings.
|
|
60
|
+
- Validate and replace parts of datetime strings to ensure accuracy and consistency.
|
|
61
|
+
- Strip time and timezone information from datetime strings when needed.
|
|
62
|
+
|
|
63
|
+
4. **Performance Optimizations**:
|
|
64
|
+
- Utilizes Cython to enhance performance for computationally intensive tasks.
|
|
65
|
+
- Interfaces with underlying C code to perform high-speed string operations and date validations.
|
|
66
|
+
|
|
67
|
+
#### Solving Windows Date Formatting Issues
|
|
68
|
+
|
|
69
|
+
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.
|
|
70
|
+
|
|
71
|
+
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.
|
|
72
|
+
|
|
73
|
+
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.
|
|
74
|
+
|
|
75
|
+
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.
|
|
76
|
+
|
|
77
|
+
## Usage Examples - Working with Date Strings
|
|
78
|
+
|
|
79
|
+
### Importing the Module
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
# Import module
|
|
83
|
+
import dately as dtly
|
|
84
|
+
|
|
85
|
+
# Additional imports for examples
|
|
86
|
+
import pandas as pd
|
|
87
|
+
import numpy as np
|
|
88
|
+
|
|
89
|
+
# Set variables
|
|
90
|
+
datestring = "2023-06-21"
|
|
91
|
+
datestring_list = [
|
|
92
|
+
'2023-06-21', '2024-06-21', '2024-07-21', '2024-08-20',
|
|
93
|
+
'2024-09-19', '2024-10-19', '2024-11-18', '2024-12-18',
|
|
94
|
+
'2025-01-17', '2025-02-16', '2025-03-18', '2025-04-17'
|
|
95
|
+
]
|
|
96
|
+
datestring_array = np.array(datestring_list)
|
|
97
|
+
datestring_series = pd.Series(datestring_list)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
### Extracting Datetime Components
|
|
104
|
+
|
|
105
|
+
#### Single Date String
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
print(dtly.dt.extract_datetime_component(datestring, "year"))
|
|
109
|
+
# Output: '2023'
|
|
110
|
+
|
|
111
|
+
print(dtly.dt.extract_datetime_component(datestring, "day"))
|
|
112
|
+
# Output: '21'
|
|
113
|
+
|
|
114
|
+
print(dtly.dt.extract_datetime_component(datestring, "month"))
|
|
115
|
+
# Output: '06'
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### List of Date Strings
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
print(dtly.dt.extract_datetime_component(datestring_list, "year"))
|
|
122
|
+
# Output: ['2023', '2024', '2024', '2024', '2024', '2024', '2024', '2024', '2025', '2025', '2025', '2025']
|
|
123
|
+
|
|
124
|
+
print(dtly.dt.extract_datetime_component(datestring_list, "day"))
|
|
125
|
+
# Output: ['21', '21', '21', '20', '19', '19', '18', '18', '17', '16', '18', '17']
|
|
126
|
+
|
|
127
|
+
print(dtly.dt.extract_datetime_component(datestring_list, "month"))
|
|
128
|
+
# Output: ['06', '06', '07', '08', '09', '10', '11', '12', '01', '02', '03', '04']
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### NumPy Array of Date Strings
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
print(dtly.dt.extract_datetime_component(datestring_array, "year"))
|
|
135
|
+
# Output: array(['2023', '2024', '2024', '2024', '2024', '2024', '2024', '2024', '2025', '2025', '2025', '2025'], dtype=object)
|
|
136
|
+
|
|
137
|
+
print(dtly.dt.extract_datetime_component(datestring_array, "day"))
|
|
138
|
+
# Output: array(['21', '21', '21', '20', '19', '19', '18', '18', '17', '16', '18', '17'], dtype=object)
|
|
139
|
+
|
|
140
|
+
print(dtly.dt.extract_datetime_component(datestring_array, "month"))
|
|
141
|
+
# Output: array(['06', '06', '07', '08', '09', '10', '11', '12', '01', '02', '03', '04'], dtype=object)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### Pandas Series of Date Strings
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
print(dtly.dt.extract_datetime_component(datestring_series, "year"))
|
|
148
|
+
# Output:
|
|
149
|
+
# 0 2023
|
|
150
|
+
# 1 2024
|
|
151
|
+
# 2 2024
|
|
152
|
+
# 3 2024
|
|
153
|
+
# 4 2024
|
|
154
|
+
# 5 2024
|
|
155
|
+
# 6 2024
|
|
156
|
+
# 7 2024
|
|
157
|
+
# 8 2025
|
|
158
|
+
# 9 2025
|
|
159
|
+
# 10 2025
|
|
160
|
+
# 11 2025
|
|
161
|
+
# dtype: object
|
|
162
|
+
|
|
163
|
+
print(dtly.dt.extract_datetime_component(datestring_series, "day"))
|
|
164
|
+
# Output:
|
|
165
|
+
# 0 21
|
|
166
|
+
# 1 21
|
|
167
|
+
# 2 21
|
|
168
|
+
# 3 20
|
|
169
|
+
# 4 19
|
|
170
|
+
# 5 19
|
|
171
|
+
# 6 18
|
|
172
|
+
# 7 18
|
|
173
|
+
# 8 17
|
|
174
|
+
# 9 16
|
|
175
|
+
# 10 18
|
|
176
|
+
# 11 17
|
|
177
|
+
# dtype: object
|
|
178
|
+
|
|
179
|
+
print(dtly.dt.extract_datetime_component(datestring_series, "month"))
|
|
180
|
+
# Output:
|
|
181
|
+
# 0 06
|
|
182
|
+
# 1 06
|
|
183
|
+
# 2 07
|
|
184
|
+
# 3 08
|
|
185
|
+
# 4 09
|
|
186
|
+
# 5 10
|
|
187
|
+
# 6 11
|
|
188
|
+
# 7 12
|
|
189
|
+
# 8 01
|
|
190
|
+
# 9 02
|
|
191
|
+
# 10 03
|
|
192
|
+
# 11 04
|
|
193
|
+
# dtype: object
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
### Detecting Datetime Formats
|
|
200
|
+
|
|
201
|
+
#### Single Date String
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
print(dtly.dt.detect_date_format(datestring))
|
|
205
|
+
# Output: '%Y-%m-%d'
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### List of Date Strings
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
print(dtly.dt.detect_date_format(datestring_list))
|
|
212
|
+
# Output: ['%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d']
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
#### NumPy Array of Date Strings
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
print(dtly.dt.detect_date_format(datestring_array))
|
|
219
|
+
# Output: array(['%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d', '%Y-%m-%d'], dtype=object)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
#### Pandas Series of Date Strings
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
print(dtly.dt.detect_date_format(datestring_series))
|
|
226
|
+
# Output:
|
|
227
|
+
# 0 %Y-%m-%d
|
|
228
|
+
# 1 %Y-%m-%d
|
|
229
|
+
# 2 %Y-%m-%d
|
|
230
|
+
# 3 %Y-%m-%d
|
|
231
|
+
# 4 %Y-%m-%d
|
|
232
|
+
# 5 %Y-%m-%d
|
|
233
|
+
# 6 %Y-%m-%d
|
|
234
|
+
# 7 %Y-%m-%d
|
|
235
|
+
# 8 %Y-%m-%d
|
|
236
|
+
# 9 %Y-%m-%d
|
|
237
|
+
# 10 %Y-%m-%d
|
|
238
|
+
# 11 %Y-%m-%d
|
|
239
|
+
# dtype: object
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
### Converting Dates
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
# Converting a single date string
|
|
250
|
+
print(dtly.dt.convert_date(datestring, to_format='%m.%Y/%d %I:%M %p', delta=1))
|
|
251
|
+
# Output: '06.2023/22 12:00 AM'
|
|
252
|
+
|
|
253
|
+
# Converting a list of date strings
|
|
254
|
+
print(dtly.dt.convert_date(datestring_list, to_format='%Y/%m/%d %I:%M:%S %p'))
|
|
255
|
+
# Output: ['2023/06/21 12:00:00 AM', '2024/06/21 12:00:00 AM', '2024/07/21 12:00:00 AM', '2024/08/20 12:00:00 AM', '2024/09/19 12:00:00 AM', '2024/10/19 12:00:00 AM', '2024/11/18 12:00:00 AM', '2024/12/18 12:00:00 AM', '2025/01/17 12:00:00 AM', '2025/02/16 12:00:00 AM', '2025/03/18 12:00:00 AM', '2025/04/17 12:00:00 AM']
|
|
256
|
+
|
|
257
|
+
# Converting a NumPy array of date strings
|
|
258
|
+
print(dtly.dt.convert_date(datestring_array, to_format='%y/%m-%d %H:%M'))
|
|
259
|
+
# Output: array(['23/06-21 00:00', '24/06-21 00:00', '24/07-21 00:00', '24/08-20 00:00', '24/09-19 00:00', '24/10-19 00:00', '24/11-18 00:00', '24/12-18 00:00', '25/01-17 00:00', '25/02-16 00:00', '25/03-18 00:00', '25/04-17 00:00'], dtype=object)
|
|
260
|
+
|
|
261
|
+
# Converting a Pandas Series of date strings
|
|
262
|
+
print(dtly.dt.convert_date(datestring_series, to_format='%Y.%m.%d'))
|
|
263
|
+
# Output:
|
|
264
|
+
# 0 2023.06.21
|
|
265
|
+
# 1 2024.06.21
|
|
266
|
+
# 2 2024.07.21
|
|
267
|
+
# 3 2024.08.20
|
|
268
|
+
# 4 2024.09.19
|
|
269
|
+
# 5 2024.10.19
|
|
270
|
+
# 6 2024.11.18
|
|
271
|
+
# 7 2024.12.18
|
|
272
|
+
# 8 2025.01.17
|
|
273
|
+
# 9 2025.02.16
|
|
274
|
+
# 10 2025.03.18
|
|
275
|
+
# 11 2025.04.17
|
|
276
|
+
# dtype: object
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Converting Dates in Dictionaries
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
# Sample dictionary with dates
|
|
283
|
+
sample_dict = {
|
|
284
|
+
"event": {
|
|
285
|
+
"name": "Annual Conference",
|
|
286
|
+
"dates": {
|
|
287
|
+
"start_date": "2024-01-15",
|
|
288
|
+
"end_date": "2024-01-20"
|
|
289
|
+
},
|
|
290
|
+
"registration": {
|
|
291
|
+
"open_date": "2023-11-01",
|
|
292
|
+
"close_date": "2023-12-30"
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
"meetings": [
|
|
296
|
+
{
|
|
297
|
+
"title": "Planning Meeting",
|
|
298
|
+
"meeting_date": "2023-10-01"
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
"title": "Review Meeting",
|
|
302
|
+
"meeting_date": "2023-10-15"
|
|
303
|
+
}
|
|
304
|
+
],
|
|
305
|
+
"webinars": [
|
|
306
|
+
{
|
|
307
|
+
"topic": "Introduction to the Event",
|
|
308
|
+
"session_dates": [
|
|
309
|
+
"2023-11-10",
|
|
310
|
+
"2023-11-17"
|
|
311
|
+
]
|
|
312
|
+
}
|
|
313
|
+
],
|
|
314
|
+
"workshops": {
|
|
315
|
+
"sessions": [
|
|
316
|
+
{
|
|
317
|
+
"session_name": "Workshop 1",
|
|
318
|
+
"date": "01/01/2024"
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
"session_name": "Workshop 2",
|
|
322
|
+
"date": "2024-01-18"
|
|
323
|
+
}
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
# Converting dates in a dictionary
|
|
329
|
+
converted_dict = dtly.dt.convert_date(sample_dict, to_format='%Y/%m', dict_keys=["meeting_date", "date", "session_dates"])
|
|
330
|
+
print(converted_dict)
|
|
331
|
+
# Output:
|
|
332
|
+
# {'event': {'name': 'Annual Conference', 'dates': {'start_date': '2024-01-15', 'end_date': '2024-01-20'}, 'registration': {'open_date': '2023-11-01', 'close_date': '2023-12-30'}}, 'meetings': [{'title': 'Planning Meeting', 'meeting_date': '2023/10'}, {'title': 'Review Meeting', 'meeting_date': '2023/10'}], 'webinars': [{'topic': 'Introduction to the Event', 'session_dates': ['2023/11', '2023/11']}], 'workshops': {'sessions': [{'session_name': 'Workshop 1', 'date': '2024/01'}, {'session_name': 'Workshop 2', 'date': '2024/01'}]}}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
### Replacing Datestring
|
|
337
|
+
|
|
338
|
+
```python
|
|
339
|
+
# Replacing year in a single date string
|
|
340
|
+
print(dtly.dt.replace_datestring(datestring, year=2021))
|
|
341
|
+
# Output: '2021-06-21'
|
|
342
|
+
|
|
343
|
+
# Replacing month in a single date string
|
|
344
|
+
print(dtly.dt.replace_datestring(datestring, month="5"))
|
|
345
|
+
# Output: '2023-5-21'
|
|
346
|
+
|
|
347
|
+
# Replacing day in a list of date strings
|
|
348
|
+
print(dtly.dt.replace_datestring(datestring_list, day=6))
|
|
349
|
+
# Output: ['2023-06-6', '2024-06-6', '2024-07-6', '2024-08-6', '2024-09-6', '2024-10-6', '2024-11-6', '2024-12-6', '2025-01-6', '2025-02-6', '2025-03-6', '2025-04-6']
|
|
350
|
+
|
|
351
|
+
# Replacing day in a Pandas Series of date strings
|
|
352
|
+
print(dtly.dt.replace_datestring(datestring_series, day="02"))
|
|
353
|
+
# Output:
|
|
354
|
+
# 0 2023-06-02
|
|
355
|
+
# 1 2024-06-02
|
|
356
|
+
# 2 2024-07-02
|
|
357
|
+
# 3 2024-08-02
|
|
358
|
+
# 4 2024-09-02
|
|
359
|
+
# 5 2024-10-02
|
|
360
|
+
# 6 2024-11-02
|
|
361
|
+
# 7 2024-12-02
|
|
362
|
+
# 8 2025-01-02
|
|
363
|
+
# 9 2025-02-02
|
|
364
|
+
# 10 2025-03-02
|
|
365
|
+
# 11 2025-04-02
|
|
366
|
+
# dtype: object
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### Replacing Datetimestring
|
|
370
|
+
|
|
371
|
+
```python
|
|
372
|
+
# Replacing time components in a single date string
|
|
373
|
+
print(dtly.dt.replace_timestring(datestring))
|
|
374
|
+
# Output: '2023-06-21 15:17:47.50691'
|
|
375
|
+
|
|
376
|
+
print(dtly.dt.replace_timestring(datestring, hour=13))
|
|
377
|
+
# Output: '2023-06-21 13:17:47.56700'
|
|
378
|
+
|
|
379
|
+
print(dtly.dt.replace_timestring(datestring, hour="02"))
|
|
380
|
+
# Output: '2023-06-21 02:17:47.63773'
|
|
381
|
+
|
|
382
|
+
print(dtly.dt.replace_timestring(datestring, hour="02", minute=11))
|
|
383
|
+
# Output: '2023-06-21 02:11:47.69779'
|
|
384
|
+
|
|
385
|
+
print(dtly.dt.replace_timestring(datestring, hour="02", minute=10, second=44))
|
|
386
|
+
# Output: '2023-06-21 02:10:44.75777'
|
|
387
|
+
|
|
388
|
+
print(dtly.dt.replace_timestring(datestring, hour="02", minute=10, second=44, microsecond=1))
|
|
389
|
+
# Output: '2023-06-21 02:10:44.00001'
|
|
390
|
+
|
|
391
|
+
print(dtly.dt.replace_timestring(datestring, hour="02", minute=10, second=44, microsecond=1, time_indicator="AM"))
|
|
392
|
+
# Output: '2023-06-21 02:10:44.00001 AM'
|
|
393
|
+
|
|
394
|
+
# Replacing time components in an ISO date string
|
|
395
|
+
iso_datestring = "2023-06-21T12:30:00Z"
|
|
396
|
+
print(dtly.dt.replace_timestring(iso_datestring, hour=2, minute=10, second=44, microsecond=1))
|
|
397
|
+
# Output: '2023-06-21T02:10:44.000001+00:00'
|
|
398
|
+
|
|
399
|
+
print(dtly.dt.replace_timestring(iso_datestring, hour=2, minute=10, second=44, microsecond=1, tzinfo=3))
|
|
400
|
+
# Output: '2023-06-21T02:10:44.000001+03:00'
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
## Working with Time Zones
|
|
407
|
+
|
|
408
|
+
### Retrieving Time Zone Information
|
|
409
|
+
|
|
410
|
+
```python
|
|
411
|
+
# Get the list of country codes
|
|
412
|
+
dtly.TimeZoner.CountryCodes
|
|
413
|
+
# Output: ['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX'.....]
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
```python
|
|
417
|
+
# Get the list of country names
|
|
418
|
+
dtly.TimeZoner.CountryNames
|
|
419
|
+
# Output: ['Afghanistan', 'Aland Islands', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica'.....]
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
```python
|
|
423
|
+
# Get the list of time zones
|
|
424
|
+
dtly.TimeZoner.Zones
|
|
425
|
+
# Output: ['Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', 'Africa/Algiers', 'Africa/Asmara', 'Africa/Bamako', 'Africa/Bangui'.....]
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
```python
|
|
429
|
+
# Get time zones by country
|
|
430
|
+
dtly.TimeZoner.ZonesByCountry
|
|
431
|
+
# Output: {'CI': ['Africa/Abidjan'], 'GH': ['Africa/Accra'], 'ET': ['Africa/Addis_Ababa'].....]}
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
```python
|
|
435
|
+
# Get time zones by DST observance
|
|
436
|
+
dtly.TimeZoner.ObservesDST
|
|
437
|
+
# Output: {'observes_dst': ['Africa/Casablanca', 'Africa/Ceuta', 'Africa/El_Aaiun'.....]}
|
|
438
|
+
```
|
|
439
|
+
```python
|
|
440
|
+
# Get time zones by offset
|
|
441
|
+
dtly.TimeZoner.Offsets
|
|
442
|
+
# Output: {'+00:00': ['Africa/Abidjan', 'Africa/Accra', 'Africa/Bamako'.....], '+03:00': ['Africa/Addis_Ababa', 'Africa/Asmara'.....], '-09:00': ['America/Adak', 'Pacific/Gambier'.....], '-08:00': ['America/Anchorage'.....]}
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Time Zone Operations
|
|
446
|
+
|
|
447
|
+
```python
|
|
448
|
+
# Retrieve detailed information for a specific time zone
|
|
449
|
+
dtly.TimeZoner.FilterZoneDetail('America/Denver')
|
|
450
|
+
# Output: {'countryCode': 'US', 'countryName': 'United States', 'Offset': '-06:00', 'UTC offset (STD)': '-07:00', 'UTC offset (DST)': '-06:00', 'Abbreviation (STD)': 'MST', 'Abbreviation (DST)': 'MDT'}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
```python
|
|
454
|
+
# Get the current time for a specific time zone
|
|
455
|
+
dtly.TimeZoner.CurrentTimebyZone('Australia/Adelaide')
|
|
456
|
+
# Output: '2024-07-02T04:32:05.642329+09:30'
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
```python
|
|
460
|
+
# Convert time from one time zone to another
|
|
461
|
+
from_zone = 'Africa/Ceuta'
|
|
462
|
+
to_zone = 'America/Anchorage'
|
|
463
|
+
dtly.TimeZoner.ConvertTimeZone(from_zone, to_zone, year=2024, month=5, day=22, hour=12, minute=13, second=22)
|
|
464
|
+
# Output: [{'countryCode': 'ES', 'countryName': 'Spain', 'zoneName': 'Africa/Ceuta', 'gmtOffset': 7200, 'timestamp': 1719865256}, {'countryCode': 'US', 'countryName': 'United States', 'zoneName': 'America/Anchorage', 'gmtOffset': -28800, 'timestamp': 1719829256}]
|
|
465
|
+
```
|