This code generates a list of formatted dates for use in tagging, organization, or logging.
By following this guide, you can learn how to input various settings and understand how each input influences the generated output.
The code prompts the user to provide details for generating a list of dates formatted with tags and ordinal suffixes. Based on the user’s preferences, it can generate dates in either chronological or reverse chronological order.
Upon running the code, the user will be prompted to enter specific details that configure the output. Here is a breakdown of each input, its purpose, and how it affects the final output.
Tags (label: "Select the Tags (Default: daily-jots)")
Type: Tag selector (expects a tag name)
Purpose: Specifies a tag to categorize the generated dates. If no tag is selected, the code uses "daily-jots" as the default tag.
Effect on Output: The chosen tag will appear as a prefix to each date in the final list.
Number of Days (label: "Select the Number of Days (Default: 10, if left blank)")
Type: String (expects a number, parsed into an integer)
Purpose: Determines the number of dates to generate, starting from the selected start date.
Effect on Output: Controls the length of the generated date list. If left blank, it defaults to 10.
Reverse Chronological Order (label: "Reverse Chronological Order (Default: Chronological)")
Type: Checkbox (Boolean)
Purpose: Sets the order in which the dates are listed.
Unchecked: Dates are listed in chronological order (earliest to latest).
Checked: Dates are listed in reverse chronological order (latest to earliest).
Effect on Output: Changes the ordering of dates based on the checkbox status.
Start Date (label: "Select the Start Date (MM/DD/YYYY)", value: <formatted today’s date>)
Type: String (expects a date in MM/DD/YYYY format)
Purpose: Specifies the starting point for generating dates. The code defaults to today’s date if the input is blank.
Effect on Output: Defines the beginning of the date range from which subsequent dates are calculated.
Prompt and Collect Inputs:
When the function runs, the user is prompted to enter values for each input listed above.
Default values are used if certain fields are left blank (e.g., “daily-jots” as the tag, today’s date as the start date, 10 days for number of days).
Process Inputs:
Each input is processed:
Tag: Defaults to "daily-jots" if not specified.
Number of Days: Converted to an integer and defaults to 10 if blank.
Start Date: Set to today’s date if left blank.
Chronological Order: Checked to determine if dates should be reversed.
Date Generation and Formatting:
The code generates dates starting from the specified start date, iterating up to the number of days entered.
Each date is formatted to include:
The tag,
The month name,
The day of the month with an ordinal suffix (e.g., "1st," "2nd," "3rd").
Ordering:
The list is reversed if reverse chronological order is selected.
Output:
The final list of dates is printed in the console for viewing or further use.
generateDates(startDate, days)Purpose: Generates and formats a series of dates.
Parameters:
startDate (Date object): Start date for the sequence.
days (integer): Number of days to generate.
Returns: Array of formatted date strings.
getSuffix(day)Purpose: Provides the correct ordinal suffix (st, nd, rd, th) for the day of the month.
Parameter:
day (integer): Day of the month.
Returns: String with the appropriate suffix.