Overview
TheDateCalculatorViewModel class manages date calculations, including calculating the difference between two dates and adding/subtracting days, months, and years from a starting date.
Namespace: CalculatorApp.ViewModel
Implements: Windows::UI::Xaml::Data::INotifyPropertyChanged
Declared in: DateCalculatorViewModel.h:15
Observable Properties
Mode Properties
IsDateDiffMode
true, calculates the difference between two dates.
IsAddMode
true, adds or subtracts an offset from a start date.
Input Properties (Date Difference Mode)
FromDate
ToDate
Input Properties (Add/Subtract Mode)
StartDate
DaysOffset
MonthsOffset
YearsOffset
OffsetValues
c_maxOffsetValue = 999
Output Properties (Date Difference Mode)
StrDateDiffResult
StrDateDiffResultInDays
IsDiffInDays
StrDateDiffResultAutomationName
Output Properties (Add/Subtract Mode)
StrDateResult
StrDateResultAutomationName
Commands
CopyCommand
Key Methods
Constructor
Private Methods
OnPropertyChanged
OnInputsChanged
UpdateDisplayResult
GetDateDiffString
GetDateDiffStringInDays
GetLocalizedNumberString
ClipTime
INotifyPropertyChanged Implementation
The ViewModel uses theOBSERVABLE_OBJECT_CALLBACK macro:
OnPropertyChanged method for custom logic.
Property Macro Usage
Observable Property Example
Custom Property Example
TheFromDate, ToDate, and StartDate properties are implemented manually to call RaisePropertyChanged:
Usage Examples
Date Difference Mode
Add/Subtract Mode
Binding to XAML
Accessibility
The ViewModel provides separate automation names for screen readers:StrDateDiffResultAutomationName- Narrator-friendly date differenceStrDateResultAutomationName- Narrator-friendly result date
Localization
The ViewModel uses the current system locale for:- Date formatting (
DateTimeFormatter) - Number formatting (
GetLocalizedNumberString) - List separators in results
See Also
- ApplicationViewModel - Application-level state management
- DateCalculationEngine - Date calculation logic