LoadDateLogHandle

Populate a date log handle with dates from file or generate date range with optional merge operations

Overview

LoadDateLogHandle is the primary function for populating date collections with data. It supports three modes of operation: loading from file (for DateLog and Holidays), generating date ranges (for DateRange), and automatic merging with conflict resolution. The function handles multi-threaded parsing, validation, and automatic date range generation to extend collections beyond file data.

Purpose

This is a comprehensive loader that serves multiple purposes:

Key Features

Function Signature


             HRESULT _Must_inspect_result_ _Success_(SUCCEEDED(return)) LoadDateLogHandle(
                 _In_opt_  PFILE_INFO                                                              pFileInfo,
                 _In_opt_  _When_(pFileInfo == NULL, _Notnull_) DATE_ITEM_HANDLE                   hStartDate,
                 _In_opt_  _When_(pFileInfo == NULL, _Notnull_) DATE_ITEM_HANDLE                   hEndDate,
                 _In_	 DATE_LOG_HANDLE                                                           hDateLogHandle,
                 _In_opt_ PDATE_COLLECTION_PROGRESS                                                pProgData,
                 _In_ DWORD                                                                        dwFlags
             );
            

Calling Convention

Standard C calling convention with SAL annotations for parameter validation and return value inspection.

Parameters

pFileInfo

[In, Optional] PFILE_INFO

File to parse for date data. Mutually exclusive with hStartDate/hEndDate.

  • If provided: dates are loaded from file
  • If NULL: dates are generated from hStartDate to hEndDate
  • Must be valid FILE_INFO for DateLog and Holidays types
  • File is parsed using multi-threaded chunk processing
hStartDate

[In, Optional] DATE_ITEM_HANDLE

Start date for range generation. Required when pFileInfo is NULL.

  • Must be non-NULL if pFileInfo is NULL
  • Must be a valid DATE_ITEM_HANDLE
  • Cannot be a market holiday (must be business day)
  • Must be less than or equal to hEndDate
hEndDate

[In, Optional] DATE_ITEM_HANDLE

End date for range generation. Required when pFileInfo is NULL for DateRange.

  • Must be non-NULL if pFileInfo is NULL for range generation
  • Must be a valid DATE_ITEM_HANDLE
  • Must be covered by holidays handle (not a holiday itself)
  • Must be greater than hStartDate
  • Cannot be in the future relative to current market dates
hDateLogHandle

[In] DATE_LOG_HANDLE

Target handle to populate. Type determines loading behavior.

  • Must be valid handle created by InitializeDateLogHandle()
  • For DateLog: Can load from file or generate range
  • For DateRange: Can load from file or generate range
  • For Holidays: Must load from file (no generation)
  • Handle is modified in-place
pProgData

[In, Optional] PDATE_COLLECTION_PROGRESS

Progress callback structure for reporting parsing progress.

  • If NULL: no progress reporting
  • If provided: must contain valid hMutex
  • Caller fills in dwMaxCount; function updates dwCount
  • Useful for large file parsing with UI updates
dwFlags

[In] DWORD

Behavior flags controlling merge and generation options.

Flag Value Behavior
DATE_RANGE_MERGE_FAVOR_SOURCE 0x08 When extending log, use source UUIDs for overlapping dates
DATE_RANGE_MERGE_FAVOR_DEST 0x04 When extending log, keep destination UUIDs for overlapping dates
PARSE_VERIFY_ENABLE_FLAG 0x40 Verify consecutive market days during parsing

Return Values

Success

S_OK (0x00000000)

Handle successfully populated with date data.

Validation Errors

ERROR_INVALID_PARAMETER (0x80070057)

Invalid parameter combination or NULL handle.

ERR_INVALID_DATELOG_HANDLE

The provided hDateLogHandle is invalid or corrupted.

ERR_INVALID_HOLIDAY_HANDLE

The holidays handle within the datelog is invalid.

ERR_DATE_NO_COVERED

End date is not covered by holidays (is a holiday itself).

Range Generation Errors

ERR_MAX_DATELOG_REACHED

Date range gap exceeds available capacity or DATE_LOG_MAX limit.

ERR_DATELOG_ZERO_GAP

Start and end dates are same or have zero market days between them.

File Processing Errors

ERROR_FILE_CORRUPT

Date records in file are malformed or unreadable.

ERROR_READ_FAULT

Error reading file data or insufficient data in file.

Resource Errors

ERROR_OUTOFMEMORY (0x80000002)

Insufficient memory for parsing or range generation.

Behavior by Handle Type

DateLog Handle

With pFileInfo:
  • Parse date log file using multi-threaded processing
  • If hEndDate provided and log is not current: generate range from last date to hEndDate
  • Automatically merge generated range into log
  • Convert result back to DateLog type after merge
  • Update file if modifications made
With hStartDate/hEndDate:
  • Generate date range between dates
  • Populate handle with generated dates
  • Create temporary file for range storage
  • No file parsing involved

DateRange Handle

With pFileInfo or hStartDate/hEndDate:
  • Parse date log file or generate dates between specified range
  • Skip weekends and holidays automatically
  • Create temporary file for range storage
  • Ready for merge operations

Holidays Handle

With pFileInfo (Required):
  • Parse holidays from file
  • No date generation allowed
  • Multi-threaded parsing enabled

Usage Examples

Example 1: Load Date Log from File

                    // Create date log and holidays
                    HOLIDAYS_HANDLE hHolidays = NULL;
                    InitializeDateLogHandle(NULL, 0, NULL, &hHolidays, HandleIsForHolidays);

                    PFILE_INFO pHolidaysFile = /* load holidays file */;
                    LoadDateLogHandle(pHolidaysFile, NULL, NULL, hHolidays, NULL, 0);

                    // Create and load date log from file
                    DATE_LOG_HANDLE hDateLog = NULL;
                    InitializeDateLogHandle(NULL, 0, hHolidays, &hDateLog, HandleIsForDatelog);

                    PFILE_INFO pDateFile = /* load date log file */;
                    HRESULT hr = LoadDateLogHandle(
                        pDateFile,           // File with date data
                        NULL,
                        NULL,
                        hDateLog,
                        NULL,
                        0
                    );

                    if (SUCCEEDED(hr)) {
                        DWORD count = GetDateCollectionLength(hDateLog);
                        printf("Loaded %d dates from file\n", count);
                    }
             
Example 2: Generate Date Range and Merge

                    // Create range handle
                    DATE_RANGE_HANDLE hRange = NULL;
                    InitializeDateLogHandle(NULL, 10000, hHolidays, &hRange, HandleIsForRange);

                    // Generate dates from start to end
                    DATE_ITEM_HANDLE hStart = /* ... */;
                    DATE_ITEM_HANDLE hEnd = /* ... */;

                    HRESULT hr = LoadDateLogHandle(
                        NULL,               // No file
                        hStart,             // Start date for generation
                        hEnd,               // End date for generation
                        hRange,             // Target range
                        NULL,
                        0
                    );

                    if (SUCCEEDED(hr)) {
                        hr = MergeDateLogHandle(hMainLog, hRange,
                        DATE_RANGE_MERGE_FAVOR_SOURCE);
                    }

                    FreeDateCollectionHandle(hRange);
            

Performance Considerations

File Parsing

Date Range Generation

Important Notes

Automatic Merge: When extending a DateLog beyond file data with hEndDate, automatic merging occurs. The generated range is merged according to dwFlags.
File Format: Date files must follow MDTS format with records of exactly 48 bytes: GUID:YYYY-MM-DD,. Malformed records cause parsing to fail.
Holiday Coverage: All generated dates are validated against the holidays handle. If hEndDate falls on or after a holiday, generation fails.

Related Functions