Skip to content

Instantly share code, notes, and snippets.

@decagondev
Created September 23, 2025 19:36
Show Gist options
  • Save decagondev/6f92c500260161952bda722e5dc27866 to your computer and use it in GitHub Desktop.
Save decagondev/6f92c500260161952bda722e5dc27866 to your computer and use it in GitHub Desktop.

Ticket 2: Implement StringToFileTime Helper Function

Description

Create a utility function to parse a date string in YYYY-MM-DD format into a FILETIME struct. This will be used for date filtering in later tickets. Test in main() with sample dates, converting and printing success/failure or verifying FILETIME values.

Acceptance Criteria

  • Function signature: bool StringToFileTime(const std::wstring& dateStr, FILETIME& fileTime)
  • Uses swscanf_s for parsing and SystemTimeToFileTime for conversion.
  • Returns false on invalid format.
  • In main(): Test valid and invalid date strings and print results.

Starter Boilerplate Code

#include <windows.h>
#include <iostream>
#include <string>

/**
 * @brief Converts a date string in the format "YYYY-MM-DD" to a Windows FILETIME structure.
 *
 * This function takes a wide-character string representing a date in the format "YYYY-MM-DD"
 * and attempts to parse it into year, month, and day components. It then converts these
 * components into a SYSTEMTIME structure and subsequently into a FILETIME structure.
 * The function returns true if the conversion is successful, or false if the input string
 * is not in the correct format or the conversion fails.
 *
 * @param dateStr A wide-character string (std::wstring) containing the date in "YYYY-MM-DD" format.
 * @param fileTime A reference to a FILETIME structure where the converted time will be stored.
 * @return bool True if the conversion succeeds, false otherwise.
 */
bool StringToFileTime(const std::wstring& dateStr, FILETIME& fileTime) {
    return false;
}

int main() {
    FILETIME ft;
    
    if (StringToFileTime(L"2023-01-01", ft)) {
        std::wcout << L"Valid date: 2023-01-01" << std::endl;
    } else {
        std::wcout << L"Invalid date: 2023-01-01" << std::endl;
    }
    
    if (StringToFileTime(L"invalid", ft)) {
        std::wcout << L"Valid date: invalid" << std::endl;
    } else {
        std::wcout << L"Invalid date: invalid" << std::endl;
    }
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment