forked from microsoft/calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateCalculatorViewModel.h
186 lines (162 loc) · 7.03 KB
/
DateCalculatorViewModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include "Common/Utils.h"
#include "Common/DateCalculator.h"
const int c_maxOffsetValue = 999;
namespace CalculatorApp
{
namespace ViewModel
{
[Windows::UI::Xaml::Data::Bindable] public ref class DateCalculatorViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
{
public:
DateCalculatorViewModel();
OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged);
// Input Properties
OBSERVABLE_PROPERTY_RW(bool, IsDateDiffMode);
OBSERVABLE_PROPERTY_RW(bool, IsAddMode);
OBSERVABLE_PROPERTY_R(bool, IsDiffInDays); // If diff is only in days or the dates are the same,
// then show only one result and avoid redundancy
OBSERVABLE_PROPERTY_RW(int, DaysOffset);
OBSERVABLE_PROPERTY_RW(int, MonthsOffset);
OBSERVABLE_PROPERTY_RW(int, YearsOffset);
// Read only property for offset values
property Windows::Foundation::Collections::IVector<Platform::String^>^ OffsetValues
{
Windows::Foundation::Collections::IVector<Platform::String^>^ get() { return m_offsetValues; }
}
// From date for Date Diff
property Windows::Foundation::DateTime FromDate
{
Windows::Foundation::DateTime get()
{
return m_fromDate;
}
void set(Windows::Foundation::DateTime value)
{
if (m_fromDate.UniversalTime != value.UniversalTime)
{
m_fromDate = value;
RaisePropertyChanged("FromDate");
}
}
}
// To date for Date Diff
property Windows::Foundation::DateTime ToDate
{
Windows::Foundation::DateTime get()
{
return m_toDate;
}
void set(Windows::Foundation::DateTime value)
{
if (m_toDate.UniversalTime != value.UniversalTime)
{
m_toDate = value;
RaisePropertyChanged("ToDate");
}
}
}
// Start date for Add/Subtract date
property Windows::Foundation::DateTime StartDate
{
Windows::Foundation::DateTime get()
{
return m_startDate;
}
void set(Windows::Foundation::DateTime value)
{
if (m_startDate.UniversalTime != value.UniversalTime)
{
m_startDate = value;
RaisePropertyChanged("StartDate");
}
}
}
// Output Properties
OBSERVABLE_PROPERTY_R(Platform::String ^, StrDateDiffResult);
OBSERVABLE_PROPERTY_R(Platform::String ^, StrDateDiffResultAutomationName);
OBSERVABLE_PROPERTY_R(Platform::String ^, StrDateDiffResultInDays);
OBSERVABLE_PROPERTY_R(Platform::String ^, StrDateResult);
OBSERVABLE_PROPERTY_R(Platform::String ^, StrDateResultAutomationName);
COMMAND_FOR_METHOD(CopyCommand, DateCalculatorViewModel::OnCopyCommand);
void OnCopyCommand(Platform::Object ^ parameter);
private:
void OnPropertyChanged(_In_ Platform::String ^ prop);
void OnInputsChanged();
void UpdateDisplayResult();
void UpdateStrDateDiffResultAutomationName();
void UpdateStrDateResultAutomationName();
void InitializeDateOutputFormats(Platform::String ^ calendarIdentifier);
Platform::String ^ GetDateDiffString() const;
Platform::String ^ GetDateDiffStringInDays() const;
Platform::String ^ GetLocalizedNumberString(int value) const;
static Windows::Foundation::DateTime ClipTime(Windows::Foundation::DateTime dateTime, bool adjustUsingLocalTime = false);
property bool IsOutOfBound
{
bool get()
{
return m_isOutOfBound;
}
void set(bool value)
{
m_isOutOfBound = value;
UpdateDisplayResult();
}
}
property CalculatorApp::ViewModel::Common::DateCalculation::DateDifference DateDiffResult
{
CalculatorApp::ViewModel::Common::DateCalculation::DateDifference get()
{
return m_dateDiffResult;
}
void set(CalculatorApp::ViewModel::Common::DateCalculation::DateDifference value)
{
m_dateDiffResult = value;
UpdateDisplayResult();
}
}
property CalculatorApp::ViewModel::Common::DateCalculation::DateDifference DateDiffResultInDays
{
CalculatorApp::ViewModel::Common::DateCalculation::DateDifference get()
{
return m_dateDiffResultInDays;
}
void set(CalculatorApp::ViewModel::Common::DateCalculation::DateDifference value)
{
m_dateDiffResultInDays = value;
UpdateDisplayResult();
}
}
property Windows::Foundation::DateTime DateResult
{
Windows::Foundation::DateTime get()
{
return m_dateResult;
}
void set(Windows::Foundation::DateTime value)
{
m_dateResult = value;
UpdateDisplayResult();
}
}
private:
// Property variables
bool m_isOutOfBound;
Platform::Collections::Vector<Platform::String ^> ^ m_offsetValues;
Windows::Foundation::DateTime m_fromDate;
Windows::Foundation::DateTime m_toDate;
Windows::Foundation::DateTime m_startDate;
Windows::Foundation::DateTime m_dateResult;
CalculatorApp::ViewModel::Common::DateCalculation::DateDifference m_dateDiffResult;
CalculatorApp::ViewModel::Common::DateCalculation::DateDifference m_dateDiffResultInDays;
// Private members
CalculatorApp::ViewModel::Common::DateCalculation::DateCalculationEngine ^ m_dateCalcEngine;
CalculatorApp::ViewModel::Common::DateCalculation::DateUnit m_daysOutputFormat;
CalculatorApp::ViewModel::Common::DateCalculation::DateUnit m_allDateUnitsOutputFormat;
Windows::Globalization::DateTimeFormatting::DateTimeFormatter ^ m_dateTimeFormatter;
std::wstring m_listSeparator;
};
}
}