-
Notifications
You must be signed in to change notification settings - Fork 29
Function `baltic.calendarDate`
Barney Potter edited this page Oct 14, 2024
·
1 revision
The calendarDate()
function in BALTIC converts decimal dates back to a specified calendar date format. This function is essentially the inverse of decimalDate()
.
def calendarDate(timepoint, fmt='%Y-%m-%d')
-
timepoint
(float): The decimal representation of the date. -
fmt
(str): The desired format of the output date string. Default is '%Y-%m-%d'.
- str: The date in the specified calendar format.
- Extracts the year from the decimal date.
- Calculates the remaining fraction of the year.
- Converts this fraction to a timedelta.
- Adds the timedelta to the beginning of the year to get the exact date and time.
- Formats the resulting datetime object according to the specified format.
- Converting decimal dates back to calendar dates for human-readable output.
- Preparing date labels for time axis in plots.
- Reversing decimal date calculations for data presentation.
- Generating date strings in specific formats from numerical time representations.
import baltic as bt
# Basic usage
print(bt.calendarDate(2023.3923497267758))
# Output: '2023-05-24'
# Custom output format
print(bt.calendarDate(2023.5, fmt='%B %d, %Y'))
# Output: 'July 02, 2023'
# Year-only output
print(bt.calendarDate(2023.0, fmt='%Y'))
# Output: '2023'
# Precise timestamp output
print(bt.calendarDate(2023.75, fmt='%Y-%m-%d %H:%M:%S'))
# Output: '2023-10-01 00:00:00'
- The function handles leap years correctly, ensuring accurate date calculations.
- The precision of the output depends on the format string provided. For example, using '%Y' will only return the year, regardless of the decimal portion of the input.
- This function is particularly useful when you need to convert numerical time representations (often used in calculations or visualizations) back to human-readable dates.
- If you need to round the date to a specific precision (e.g., to the nearest day), you might need to apply rounding to the input
timepoint
before calling this function. - The function assumes that the input
timepoint
is a valid decimal date (e.g., 2023.5 for midyear). Invalid inputs may produce unexpected results.
Wiki written with the assistance of claude.ai 3.5 "Sonnet".
- Core
baltic
classes:-
Class
tree
- Tree Construction and Manipulation methods
- Tree Analysis methods
- Tree Conversion and Output methods
- Tree Visualization
- Utility Methods
- Class
leaf
- Class
node
- Class
clade
- Class
reticulation
-
Class