mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 22:23:29 -07:00
fix script and re apply style
This commit is contained in:
parent
e07f53d053
commit
f65610daff
9 changed files with 1077 additions and 793 deletions
|
@ -5,10 +5,6 @@ function usage {
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Variable that will hold the name of the clang-format command
|
# Variable that will hold the name of the clang-format command
|
||||||
FMT=""
|
FMT=""
|
||||||
|
|
||||||
|
@ -29,33 +25,22 @@ if [ -z "$FMT" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
SRC_PATH="$@"
|
||||||
|
if [ -z "$SRC_PATH" ]; then
|
||||||
|
SRC_PATH="../../../src"
|
||||||
|
fi
|
||||||
|
|
||||||
# Check all of the arguments first to make sure they're all directories
|
# Check all of the arguments first to make sure they're all directories
|
||||||
for dir in "$@"; do
|
for dir in "$SRC_PATH"; do
|
||||||
if [ ! -d "${dir}" ]; then
|
if [ ! -d "${dir}" ]; then
|
||||||
echo "${dir} is not a directory"
|
echo "${dir} is not a directory"
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Find a dominating file, starting from a given directory and going up.
|
|
||||||
find-dominating-file() {
|
|
||||||
if [ -r "$1"/"$2" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
if [ "$1" = "/" ]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
find-dominating-file "$(realpath "$1"/..)" "$2"
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run clang-format -i on all of the things
|
# Run clang-format -i on all of the things
|
||||||
for dir in "$@"; do
|
for dir in "$SRC_PATH"; do
|
||||||
pushd "${dir}" &>/dev/null
|
pushd "${dir}" &>/dev/null
|
||||||
if ! find-dominating-file . .clang-format; then
|
|
||||||
echo "Failed to find dominating .clang-format starting at $PWD"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
find . \
|
find . \
|
||||||
\( -name '*.c' \
|
\( -name '*.c' \
|
||||||
-o -name '*.cc' \
|
-o -name '*.cc' \
|
||||||
|
@ -63,6 +48,6 @@ for dir in "$@"; do
|
||||||
-o -name '*.h' \
|
-o -name '*.h' \
|
||||||
-o -name '*.hh' \
|
-o -name '*.hh' \
|
||||||
-o -name '*.hpp' \) \
|
-o -name '*.hpp' \) \
|
||||||
-exec "${FMT}" -i '{}' \;
|
-exec "${FMT}" -style=file -i '{}' \;
|
||||||
popd &>/dev/null
|
popd &>/dev/null
|
||||||
done
|
done
|
|
@ -15,10 +15,7 @@ using namespace Windows::Foundation;
|
||||||
using namespace Windows::System;
|
using namespace Windows::System;
|
||||||
using namespace Windows::ApplicationModel::DataTransfer;
|
using namespace Windows::ApplicationModel::DataTransfer;
|
||||||
|
|
||||||
String^ CopyPasteManager::supportedFormats[] =
|
String ^ CopyPasteManager::supportedFormats[] = { StandardDataFormats::Text };
|
||||||
{
|
|
||||||
StandardDataFormats::Text
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr wstring_view c_validCharacterSet{ L"0123456789()+-*/.abcdefABCDEF" };
|
static constexpr wstring_view c_validCharacterSet{ L"0123456789()+-*/.abcdefABCDEF" };
|
||||||
|
|
||||||
|
@ -40,43 +37,26 @@ static const wstring c_binProgrammerChars = L"[0-1]+((_|'|`)[0-1]+)*";
|
||||||
static const wstring c_uIntSuffixes = L"[uU]?[lL]{0,2}";
|
static const wstring c_uIntSuffixes = L"[uU]?[lL]{0,2}";
|
||||||
|
|
||||||
// RegEx Patterns used by various modes
|
// RegEx Patterns used by various modes
|
||||||
static const array<wregex, 1> standardModePatterns =
|
static const array<wregex, 1> standardModePatterns = { wregex(c_wspc + c_signedDecFloat + c_wspc) };
|
||||||
{
|
static const array<wregex, 2> scientificModePatterns = { wregex(L"(" + c_wspc + L"[-+]?)|(" + c_wspcLParenSigned + L")" + c_signedDecFloat + c_wspcRParens),
|
||||||
wregex(c_wspc + c_signedDecFloat + c_wspc)
|
wregex(L"(" + c_wspc + L"[-+]?)|(" + c_wspcLParenSigned + L")" + c_signedDecFloat
|
||||||
};
|
+ L"[e]([+]|[-])+\\d+" + c_wspcRParens) };
|
||||||
static const array<wregex, 2> scientificModePatterns =
|
static const array<array<wregex, 5>, 4> programmerModePatterns = {
|
||||||
{
|
{ // Hex numbers like 5F, 4A0C, 0xa9, 0xFFull, 47CDh
|
||||||
wregex(L"(" + c_wspc + L"[-+]?)|(" + c_wspcLParenSigned + L")" + c_signedDecFloat + c_wspcRParens),
|
{ wregex(c_wspcLParens + L"(0[xX])?" + c_hexProgrammerChars + c_uIntSuffixes + c_wspcRParens),
|
||||||
wregex(L"(" + c_wspc + L"[-+]?)|(" + c_wspcLParenSigned + L")" + c_signedDecFloat + L"[e]([+]|[-])+\\d+" + c_wspcRParens)
|
wregex(c_wspcLParens + c_hexProgrammerChars + L"[hH]?" + c_wspcRParens) },
|
||||||
};
|
// Decimal numbers like -145, 145, 0n145, 123ull etc
|
||||||
static const array<array<wregex, 5>, 4> programmerModePatterns =
|
{ wregex(c_wspcLParens + L"[-+]?" + c_decProgrammerChars + L"[lL]{0,2}" + c_wspcRParens),
|
||||||
{ {
|
wregex(c_wspcLParens + L"(0[nN])?" + c_decProgrammerChars + c_uIntSuffixes + c_wspcRParens) },
|
||||||
// Hex numbers like 5F, 4A0C, 0xa9, 0xFFull, 47CDh
|
// Octal numbers like 06, 010, 0t77, 0o77, 077ull etc
|
||||||
{
|
{ wregex(c_wspcLParens + L"(0[otOT])?" + c_octProgrammerChars + c_uIntSuffixes + c_wspcRParens) },
|
||||||
wregex(c_wspcLParens + L"(0[xX])?" + c_hexProgrammerChars + c_uIntSuffixes + c_wspcRParens),
|
// Binary numbers like 011010110, 0010110, 10101001, 1001b, 0b1001, 0y1001, 0b1001ull
|
||||||
wregex(c_wspcLParens + c_hexProgrammerChars + L"[hH]?" + c_wspcRParens)
|
{ wregex(c_wspcLParens + L"(0[byBY])?" + c_binProgrammerChars + c_uIntSuffixes + c_wspcRParens),
|
||||||
},
|
wregex(c_wspcLParens + c_binProgrammerChars + L"[bB]?" + c_wspcRParens) } }
|
||||||
// Decimal numbers like -145, 145, 0n145, 123ull etc
|
|
||||||
{
|
|
||||||
wregex(c_wspcLParens + L"[-+]?" + c_decProgrammerChars + L"[lL]{0,2}" +c_wspcRParens),
|
|
||||||
wregex(c_wspcLParens + L"(0[nN])?" + c_decProgrammerChars + c_uIntSuffixes + c_wspcRParens)
|
|
||||||
},
|
|
||||||
// Octal numbers like 06, 010, 0t77, 0o77, 077ull etc
|
|
||||||
{
|
|
||||||
wregex(c_wspcLParens + L"(0[otOT])?" + c_octProgrammerChars + c_uIntSuffixes + c_wspcRParens)
|
|
||||||
},
|
|
||||||
// Binary numbers like 011010110, 0010110, 10101001, 1001b, 0b1001, 0y1001, 0b1001ull
|
|
||||||
{
|
|
||||||
wregex(c_wspcLParens + L"(0[byBY])?" + c_binProgrammerChars + c_uIntSuffixes + c_wspcRParens),
|
|
||||||
wregex(c_wspcLParens + c_binProgrammerChars + L"[bB]?" + c_wspcRParens)
|
|
||||||
}
|
|
||||||
} };
|
|
||||||
static const array<wregex, 1> unitConverterPatterns =
|
|
||||||
{
|
|
||||||
wregex(c_wspc + L"[-+]?\\d*[.]?\\d*" + c_wspc)
|
|
||||||
};
|
};
|
||||||
|
static const array<wregex, 1> unitConverterPatterns = { wregex(c_wspc + L"[-+]?\\d*[.]?\\d*" + c_wspc) };
|
||||||
|
|
||||||
void CopyPasteManager::CopyToClipboard(String^ stringToCopy)
|
void CopyPasteManager::CopyToClipboard(String ^ stringToCopy)
|
||||||
{
|
{
|
||||||
// Copy the string to the clipboard
|
// Copy the string to the clipboard
|
||||||
auto dataPackage = ref new DataPackage();
|
auto dataPackage = ref new DataPackage();
|
||||||
|
@ -84,7 +64,7 @@ void CopyPasteManager::CopyToClipboard(String^ stringToCopy)
|
||||||
Clipboard::SetContent(dataPackage);
|
Clipboard::SetContent(dataPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
task<String^> CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
|
task<String ^> CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
|
||||||
{
|
{
|
||||||
// Retrieve the text in the clipboard
|
// Retrieve the text in the clipboard
|
||||||
auto dataPackageView = Clipboard::GetContent();
|
auto dataPackageView = Clipboard::GetContent();
|
||||||
|
@ -95,11 +75,9 @@ task<String^> CopyPasteManager::GetStringToPaste(ViewMode mode, CategoryGroupTyp
|
||||||
//-- add support to allow pasting for expressions like 1.3e12(as of now we allow 1.3e+12)
|
//-- add support to allow pasting for expressions like 1.3e12(as of now we allow 1.3e+12)
|
||||||
|
|
||||||
return create_task((dataPackageView->GetTextAsync(::StandardDataFormats::Text)))
|
return create_task((dataPackageView->GetTextAsync(::StandardDataFormats::Text)))
|
||||||
.then([mode, modeType, programmerNumberBase, bitLengthType](String^ pastedText)
|
.then([mode, modeType, programmerNumberBase,
|
||||||
{
|
bitLengthType](String ^ pastedText) { return ValidatePasteExpression(pastedText, mode, modeType, programmerNumberBase, bitLengthType); },
|
||||||
return ValidatePasteExpression(pastedText, mode, modeType, programmerNumberBase, bitLengthType);
|
task_continuation_context::use_arbitrary());
|
||||||
}
|
|
||||||
, task_continuation_context::use_arbitrary());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CopyPasteManager::ClipboardTextFormat()
|
int CopyPasteManager::ClipboardTextFormat()
|
||||||
|
@ -116,14 +94,14 @@ int CopyPasteManager::ClipboardTextFormat()
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String^ CopyPasteManager::ValidatePasteExpression(String^ pastedText, ViewMode mode, int programmerNumberBase, int bitLengthType)
|
String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode mode, int programmerNumberBase, int bitLengthType)
|
||||||
{
|
{
|
||||||
return CopyPasteManager::ValidatePasteExpression(pastedText, mode, NavCategory::GetGroupType(mode), programmerNumberBase, bitLengthType);
|
return CopyPasteManager::ValidatePasteExpression(pastedText, mode, NavCategory::GetGroupType(mode), programmerNumberBase, bitLengthType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return "NoOp" if pastedText is invalid else return pastedText
|
// return "NoOp" if pastedText is invalid else return pastedText
|
||||||
|
|
||||||
String^ CopyPasteManager::ValidatePasteExpression(String^ pastedText, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
|
String ^ CopyPasteManager::ValidatePasteExpression(String ^ pastedText, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase, int bitLengthType)
|
||||||
{
|
{
|
||||||
if (pastedText->Length() > MaxPasteableLength)
|
if (pastedText->Length() > MaxPasteableLength)
|
||||||
{
|
{
|
||||||
|
@ -135,7 +113,7 @@ String^ CopyPasteManager::ValidatePasteExpression(String^ pastedText, ViewMode m
|
||||||
wstring pasteExpression = pastedText->Data();
|
wstring pasteExpression = pastedText->Data();
|
||||||
|
|
||||||
// Get english translated expression
|
// Get english translated expression
|
||||||
String^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(pasteExpression);
|
String ^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(pasteExpression);
|
||||||
|
|
||||||
// Removing the spaces, comma separator from the pasteExpression to allow pasting of expressions like 1 + 2+1,333
|
// Removing the spaces, comma separator from the pasteExpression to allow pasting of expressions like 1 + 2+1,333
|
||||||
pasteExpression = RemoveUnwantedCharsFromWstring(englishString->Data());
|
pasteExpression = RemoveUnwantedCharsFromWstring(englishString->Data());
|
||||||
|
@ -223,7 +201,8 @@ vector<wstring> CopyPasteManager::ExtractOperands(const wstring& pasteExpression
|
||||||
if ((pasteExpression.at(i) == L'+') || (pasteExpression.at(i) == L'-'))
|
if ((pasteExpression.at(i) == L'+') || (pasteExpression.at(i) == L'-'))
|
||||||
{
|
{
|
||||||
// don't break the expression into operands if the encountered character corresponds to sign command(+-)
|
// don't break the expression into operands if the encountered character corresponds to sign command(+-)
|
||||||
if (isPreviousOpenParen || startOfExpression || isPreviousOperator || ((mode != ViewMode::Programmer) && !((i != 0) && (pasteExpression.at(i - 1) != L'e'))))
|
if (isPreviousOpenParen || startOfExpression || isPreviousOperator
|
||||||
|
|| ((mode != ViewMode::Programmer) && !((i != 0) && (pasteExpression.at(i - 1) != L'e'))))
|
||||||
{
|
{
|
||||||
isPreviousOperator = false;
|
isPreviousOperator = false;
|
||||||
continue;
|
continue;
|
||||||
|
@ -453,20 +432,22 @@ bool CopyPasteManager::TryOperandToULL(const wstring& operand, int numberBase, u
|
||||||
|
|
||||||
size_t CopyPasteManager::OperandLength(const wstring& operand, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase)
|
size_t CopyPasteManager::OperandLength(const wstring& operand, ViewMode mode, CategoryGroupType modeType, int programmerNumberBase)
|
||||||
{
|
{
|
||||||
if (modeType == CategoryGroupType::Converter) {
|
if (modeType == CategoryGroupType::Converter)
|
||||||
|
{
|
||||||
return operand.length();
|
return operand.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(mode) {
|
switch (mode)
|
||||||
case ViewMode::Standard:
|
{
|
||||||
case ViewMode::Scientific:
|
case ViewMode::Standard:
|
||||||
return StandardScientificOperandLength(operand);
|
case ViewMode::Scientific:
|
||||||
|
return StandardScientificOperandLength(operand);
|
||||||
|
|
||||||
case ViewMode::Programmer:
|
case ViewMode::Programmer:
|
||||||
return ProgrammerOperandLength(operand, programmerNumberBase);
|
return ProgrammerOperandLength(operand, programmerNumberBase);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,7 +475,6 @@ size_t CopyPasteManager::StandardScientificOperandLength(const wstring& operand)
|
||||||
|
|
||||||
size_t CopyPasteManager::ProgrammerOperandLength(const wstring& operand, int numberBase)
|
size_t CopyPasteManager::ProgrammerOperandLength(const wstring& operand, int numberBase)
|
||||||
{
|
{
|
||||||
|
|
||||||
vector<wstring> prefixes{};
|
vector<wstring> prefixes{};
|
||||||
vector<wstring> suffixes{};
|
vector<wstring> suffixes{};
|
||||||
switch (numberBase)
|
switch (numberBase)
|
||||||
|
@ -515,7 +495,7 @@ size_t CopyPasteManager::ProgrammerOperandLength(const wstring& operand, int num
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// No defined prefixes/suffixes
|
// No defined prefixes/suffixes
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// UInt suffixes are common across all modes
|
// UInt suffixes are common across all modes
|
||||||
|
|
|
@ -25,8 +25,9 @@ namespace CalculatorApp
|
||||||
class CopyPasteManager
|
class CopyPasteManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void CopyToClipboard(Platform::String^ stringToCopy);
|
static void CopyToClipboard(Platform::String ^ stringToCopy);
|
||||||
static concurrency::task<Platform::String^> GetStringToPaste(CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::CategoryGroupType modeType, int programmerNumberBase = -1, int bitLengthType = -1);
|
static concurrency::task<Platform::String ^> GetStringToPaste(CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::CategoryGroupType modeType,
|
||||||
|
int programmerNumberBase = -1, int bitLengthType = -1);
|
||||||
static bool HasStringToPaste()
|
static bool HasStringToPaste()
|
||||||
{
|
{
|
||||||
return ClipboardTextFormat() >= 0;
|
return ClipboardTextFormat() >= 0;
|
||||||
|
@ -36,25 +37,23 @@ namespace CalculatorApp
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int ClipboardTextFormat();
|
static int ClipboardTextFormat();
|
||||||
static Platform::String^ ValidatePasteExpression(
|
static Platform::String
|
||||||
Platform::String^ pastedText,
|
^ ValidatePasteExpression(Platform::String ^ pastedText, CalculatorApp::Common::ViewMode mode, int programmerNumberBase, int bitLengthType);
|
||||||
CalculatorApp::Common::ViewMode mode,
|
static Platform::String
|
||||||
int programmerNumberBase,
|
^ ValidatePasteExpression(Platform::String ^ pastedText, CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::CategoryGroupType modeType,
|
||||||
int bitLengthType);
|
int programmerNumberBase, int bitLengthType);
|
||||||
static Platform::String^ ValidatePasteExpression(
|
|
||||||
Platform::String^ pastedText,
|
|
||||||
CalculatorApp::Common::ViewMode mode,
|
|
||||||
CalculatorApp::Common::CategoryGroupType modeType,
|
|
||||||
int programmerNumberBase,
|
|
||||||
int bitLengthType);
|
|
||||||
|
|
||||||
static std::vector<std::wstring> ExtractOperands(const std::wstring& pasteExpression, CalculatorApp::Common::ViewMode mode, int programmerNumberBase = -1, int bitLengthType = -1);
|
static std::vector<std::wstring> ExtractOperands(const std::wstring& pasteExpression, CalculatorApp::Common::ViewMode mode,
|
||||||
static bool ExpressionRegExMatch(std::vector<std::wstring> operands, CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::CategoryGroupType modeType, int programmerNumberBase = -1, int bitLengthType = -1);
|
int programmerNumberBase = -1, int bitLengthType = -1);
|
||||||
|
static bool ExpressionRegExMatch(std::vector<std::wstring> operands, CalculatorApp::Common::ViewMode mode,
|
||||||
|
CalculatorApp::Common::CategoryGroupType modeType, int programmerNumberBase = -1, int bitLengthType = -1);
|
||||||
|
|
||||||
static std::pair<size_t, uint64_t> GetMaxOperandLengthAndValue(CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::CategoryGroupType modeType, int programmerNumberBase = -1, int bitLengthType = -1);
|
static std::pair<size_t, uint64_t> GetMaxOperandLengthAndValue(CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::CategoryGroupType modeType,
|
||||||
|
int programmerNumberBase = -1, int bitLengthType = -1);
|
||||||
static std::wstring SanitizeOperand(const std::wstring& operand);
|
static std::wstring SanitizeOperand(const std::wstring& operand);
|
||||||
static bool TryOperandToULL(const std::wstring& operand, int numberBase, unsigned long long int& result);
|
static bool TryOperandToULL(const std::wstring& operand, int numberBase, unsigned long long int& result);
|
||||||
static size_t OperandLength(const std::wstring& operand, CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::CategoryGroupType modeType, int programmerNumberBase = -1);
|
static size_t OperandLength(const std::wstring& operand, CalculatorApp::Common::ViewMode mode, CalculatorApp::Common::CategoryGroupType modeType,
|
||||||
|
int programmerNumberBase = -1);
|
||||||
static size_t StandardScientificOperandLength(const std::wstring& operand);
|
static size_t StandardScientificOperandLength(const std::wstring& operand);
|
||||||
static size_t ProgrammerOperandLength(const std::wstring& operand, int numberBase);
|
static size_t ProgrammerOperandLength(const std::wstring& operand, int numberBase);
|
||||||
static std::wstring RemoveUnwantedCharsFromWstring(const std::wstring& input);
|
static std::wstring RemoveUnwantedCharsFromWstring(const std::wstring& input);
|
||||||
|
@ -67,7 +66,7 @@ namespace CalculatorApp
|
||||||
static constexpr size_t MaxExponentLength = 4;
|
static constexpr size_t MaxExponentLength = 4;
|
||||||
static constexpr size_t MaxProgrammerBitLength = 64;
|
static constexpr size_t MaxProgrammerBitLength = 64;
|
||||||
|
|
||||||
static Platform::String^ supportedFormats[];
|
static Platform::String ^ supportedFormats[];
|
||||||
|
|
||||||
friend class CalculatorUnitTests::CopyPasteManagerTest;
|
friend class CalculatorUnitTests::CopyPasteManagerTest;
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,9 +30,10 @@ bool DateCalculationEngine::AddDuration(_In_ DateTime startDate, _In_ const Date
|
||||||
{
|
{
|
||||||
// The Japanese Era system can have multiple year partitions within the same year.
|
// The Japanese Era system can have multiple year partitions within the same year.
|
||||||
// For example, April 30, 2019 is denoted April 30, Heisei 31; May 1, 2019 is denoted as May 1, Reiwa 1.
|
// For example, April 30, 2019 is denoted April 30, Heisei 31; May 1, 2019 is denoted as May 1, Reiwa 1.
|
||||||
// The Calendar treats Heisei 31 and Reiwa 1 as separate years, which results in some unexpected behaviors where subtracting a year from Reiwa 1 results in a date in Heisei 31.
|
// The Calendar treats Heisei 31 and Reiwa 1 as separate years, which results in some unexpected behaviors where subtracting a year from Reiwa 1
|
||||||
// To provide the expected result across era boundaries, we first convert the Japanese era system to a Gregorian system, do date math, and then convert back to the Japanese era system.
|
// results in a date in Heisei 31. To provide the expected result across era boundaries, we first convert the Japanese era system to a Gregorian
|
||||||
// This works because the Japanese era system maintains the same year/month boundaries and durations as the Gregorian system and is only different in display value.
|
// system, do date math, and then convert back to the Japanese era system. This works because the Japanese era system maintains the same year/month
|
||||||
|
// boundaries and durations as the Gregorian system and is only different in display value.
|
||||||
if (currentCalendarSystem == CalendarIdentifiers::Japanese)
|
if (currentCalendarSystem == CalendarIdentifiers::Japanese)
|
||||||
{
|
{
|
||||||
m_calendar->ChangeCalendarSystem(CalendarIdentifiers::Gregorian);
|
m_calendar->ChangeCalendarSystem(CalendarIdentifiers::Gregorian);
|
||||||
|
@ -89,9 +90,10 @@ bool DateCalculationEngine::SubtractDuration(_In_ DateTime startDate, _In_ const
|
||||||
{
|
{
|
||||||
// The Japanese Era system can have multiple year partitions within the same year.
|
// The Japanese Era system can have multiple year partitions within the same year.
|
||||||
// For example, April 30, 2019 is denoted April 30, Heisei 31; May 1, 2019 is denoted as May 1, Reiwa 1.
|
// For example, April 30, 2019 is denoted April 30, Heisei 31; May 1, 2019 is denoted as May 1, Reiwa 1.
|
||||||
// The Calendar treats Heisei 31 and Reiwa 1 as separate years, which results in some unexpected behaviors where subtracting a year from Reiwa 1 results in a date in Heisei 31.
|
// The Calendar treats Heisei 31 and Reiwa 1 as separate years, which results in some unexpected behaviors where subtracting a year from Reiwa 1
|
||||||
// To provide the expected result across era boundaries, we first convert the Japanese era system to a Gregorian system, do date math, and then convert back to the Japanese era system.
|
// results in a date in Heisei 31. To provide the expected result across era boundaries, we first convert the Japanese era system to a Gregorian
|
||||||
// This works because the Japanese era system maintains the same year/month boundaries and durations as the Gregorian system and is only different in display value.
|
// system, do date math, and then convert back to the Japanese era system. This works because the Japanese era system maintains the same year/month
|
||||||
|
// boundaries and durations as the Gregorian system and is only different in display value.
|
||||||
if (currentCalendarSystem == CalendarIdentifiers::Japanese)
|
if (currentCalendarSystem == CalendarIdentifiers::Japanese)
|
||||||
{
|
{
|
||||||
m_calendar->ChangeCalendarSystem(CalendarIdentifiers::Gregorian);
|
m_calendar->ChangeCalendarSystem(CalendarIdentifiers::Gregorian);
|
||||||
|
|
|
@ -23,8 +23,10 @@
|
||||||
m_##n = value; \
|
m_##n = value; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
private: \
|
private: \
|
||||||
t m_##n; \
|
t m_##n; \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define PROPERTY_RW(t, n) \
|
#define PROPERTY_RW(t, n) \
|
||||||
|
@ -39,8 +41,10 @@ public:
|
||||||
m_##n = value; \
|
m_##n = value; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
private: \
|
private: \
|
||||||
t m_##n; \
|
t m_##n; \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define OBSERVABLE_PROPERTY_R(t, n) \
|
#define OBSERVABLE_PROPERTY_R(t, n) \
|
||||||
|
@ -61,8 +65,10 @@ public:
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
private: \
|
private: \
|
||||||
t m_##n; \
|
t m_##n; \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define OBSERVABLE_PROPERTY_RW(t, n) \
|
#define OBSERVABLE_PROPERTY_RW(t, n) \
|
||||||
|
@ -81,8 +87,10 @@ public:
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
private: \
|
private: \
|
||||||
t m_##n; \
|
t m_##n; \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define OBSERVABLE_NAMED_PROPERTY_R(t, n) \
|
#define OBSERVABLE_NAMED_PROPERTY_R(t, n) \
|
||||||
|
@ -92,6 +100,7 @@ public:
|
||||||
{ \
|
{ \
|
||||||
Platform::String ^ get() { return Platform::StringReference(L#n); } \
|
Platform::String ^ get() { return Platform::StringReference(L#n); } \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define OBSERVABLE_NAMED_PROPERTY_RW(t, n) \
|
#define OBSERVABLE_NAMED_PROPERTY_RW(t, n) \
|
||||||
|
@ -101,6 +110,7 @@ public:
|
||||||
{ \
|
{ \
|
||||||
Platform::String ^ get() { return Platform::StringReference(L#n); } \
|
Platform::String ^ get() { return Platform::StringReference(L#n); } \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define OBSERVABLE_PROPERTY_FIELD(n) m_##n
|
#define OBSERVABLE_PROPERTY_FIELD(n) m_##n
|
||||||
|
@ -114,6 +124,7 @@ public:
|
||||||
{ \
|
{ \
|
||||||
PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(p)); \
|
PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(p)); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
#else
|
#else
|
||||||
#define OBSERVABLE_OBJECT() \
|
#define OBSERVABLE_OBJECT() \
|
||||||
|
@ -122,6 +133,7 @@ public:
|
||||||
void RaisePropertyChanged(Platform::String ^ p) \
|
void RaisePropertyChanged(Platform::String ^ p) \
|
||||||
{ \
|
{ \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -136,6 +148,7 @@ public:
|
||||||
PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(p)); \
|
PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(p)); \
|
||||||
c(p); \
|
c(p); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
#else
|
#else
|
||||||
#define OBSERVABLE_OBJECT_CALLBACK(c) \
|
#define OBSERVABLE_OBJECT_CALLBACK(c) \
|
||||||
|
@ -145,6 +158,7 @@ public:
|
||||||
{ \
|
{ \
|
||||||
c(p); \
|
c(p); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -156,6 +170,7 @@ public:
|
||||||
if (!donotuse_##p) {\
|
if (!donotuse_##p) {\
|
||||||
donotuse_##p = CalculatorApp::Common::MakeDelegate(this, &m);\
|
donotuse_##p = CalculatorApp::Common::MakeDelegate(this, &m);\
|
||||||
} return donotuse_##p; }} private: Windows::UI::Xaml::Input::ICommand^ donotuse_##p; \
|
} return donotuse_##p; }} private: Windows::UI::Xaml::Input::ICommand^ donotuse_##p; \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define DEPENDENCY_PROPERTY_DECLARATION(t, n) \
|
#define DEPENDENCY_PROPERTY_DECLARATION(t, n) \
|
||||||
|
@ -173,6 +188,7 @@ public:
|
||||||
\
|
\
|
||||||
private: \
|
private: \
|
||||||
static Windows::UI::Xaml::DependencyProperty ^ s_##n##Property; \
|
static Windows::UI::Xaml::DependencyProperty ^ s_##n##Property; \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Utilities for DependencyProperties
|
// Utilities for DependencyProperties
|
||||||
|
@ -387,6 +403,7 @@ namespace Utils
|
||||||
#define DEPENDENCY_PROPERTY_OWNER(owner) \
|
#define DEPENDENCY_PROPERTY_OWNER(owner) \
|
||||||
private: \
|
private: \
|
||||||
typedef owner DependencyPropertiesOwner; \
|
typedef owner DependencyPropertiesOwner; \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Normal DependencyProperty
|
// Normal DependencyProperty
|
||||||
|
@ -402,6 +419,7 @@ public:
|
||||||
SetValue(s_##name##Property, value); \
|
SetValue(s_##name##Property, value); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
private: \
|
private: \
|
||||||
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
||||||
\
|
\
|
||||||
|
@ -419,6 +437,7 @@ private:
|
||||||
{ \
|
{ \
|
||||||
return Utils::RegisterDependencyProperty<DependencyPropertiesOwner, type>(L#name); \
|
return Utils::RegisterDependencyProperty<DependencyPropertiesOwner, type>(L#name); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define DEPENDENCY_PROPERTY_WITH_DEFAULT(type, name, defaultValue) \
|
#define DEPENDENCY_PROPERTY_WITH_DEFAULT(type, name, defaultValue) \
|
||||||
|
@ -433,6 +452,7 @@ public:
|
||||||
SetValue(s_##name##Property, value); \
|
SetValue(s_##name##Property, value); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
private: \
|
private: \
|
||||||
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
||||||
\
|
\
|
||||||
|
@ -450,6 +470,7 @@ private:
|
||||||
{ \
|
{ \
|
||||||
return Utils::RegisterDependencyProperty<DependencyPropertiesOwner, type>(L#name, defaultValue); \
|
return Utils::RegisterDependencyProperty<DependencyPropertiesOwner, type>(L#name, defaultValue); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define DEPENDENCY_PROPERTY_WITH_CALLBACK(type, name) \
|
#define DEPENDENCY_PROPERTY_WITH_CALLBACK(type, name) \
|
||||||
|
@ -464,6 +485,7 @@ public:
|
||||||
SetValue(s_##name##Property, value); \
|
SetValue(s_##name##Property, value); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
private: \
|
private: \
|
||||||
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
||||||
\
|
\
|
||||||
|
@ -486,6 +508,7 @@ private:
|
||||||
auto self = safe_cast<DependencyPropertiesOwner ^>(sender); \
|
auto self = safe_cast<DependencyPropertiesOwner ^>(sender); \
|
||||||
self->On##name##PropertyChanged(safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
self->On##name##PropertyChanged(safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(type, name, defaultValue) \
|
#define DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(type, name, defaultValue) \
|
||||||
|
@ -500,6 +523,7 @@ public:
|
||||||
SetValue(s_##name##Property, value); \
|
SetValue(s_##name##Property, value); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
private: \
|
private: \
|
||||||
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
||||||
\
|
\
|
||||||
|
@ -522,6 +546,7 @@ private:
|
||||||
auto self = safe_cast<DependencyPropertiesOwner ^>(sender); \
|
auto self = safe_cast<DependencyPropertiesOwner ^>(sender); \
|
||||||
self->On##name##PropertyChanged(safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
self->On##name##PropertyChanged(safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Attached DependencyProperty
|
// Attached DependencyProperty
|
||||||
|
@ -552,6 +577,7 @@ private:
|
||||||
{ \
|
{ \
|
||||||
return Utils::RegisterDependencyPropertyAttached<DependencyPropertiesOwner, type>(L#name); \
|
return Utils::RegisterDependencyPropertyAttached<DependencyPropertiesOwner, type>(L#name); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define DEPENDENCY_PROPERTY_ATTACHED_WITH_DEFAULT(type, name, defaultValue) \
|
#define DEPENDENCY_PROPERTY_ATTACHED_WITH_DEFAULT(type, name, defaultValue) \
|
||||||
|
@ -581,6 +607,7 @@ private:
|
||||||
{ \
|
{ \
|
||||||
return Utils::RegisterDependencyPropertyAttached<DependencyPropertiesOwner, type>(L#name, defaultValue); \
|
return Utils::RegisterDependencyPropertyAttached<DependencyPropertiesOwner, type>(L#name, defaultValue); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define DEPENDENCY_PROPERTY_ATTACHED_WITH_CALLBACK(type, name) \
|
#define DEPENDENCY_PROPERTY_ATTACHED_WITH_CALLBACK(type, name) \
|
||||||
|
@ -614,6 +641,7 @@ private:
|
||||||
{ \
|
{ \
|
||||||
On##name##PropertyChanged(sender, safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
On##name##PropertyChanged(sender, safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#define DEPENDENCY_PROPERTY_ATTACHED_WITH_DEFAULT_AND_CALLBACK(type, name, defaultValue) \
|
#define DEPENDENCY_PROPERTY_ATTACHED_WITH_DEFAULT_AND_CALLBACK(type, name, defaultValue) \
|
||||||
|
@ -647,6 +675,7 @@ private:
|
||||||
{ \
|
{ \
|
||||||
On##name##PropertyChanged(sender, safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
On##name##PropertyChanged(sender, safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// This goes into the cpp to initialize the static variable
|
// This goes into the cpp to initialize the static variable
|
||||||
|
|
|
@ -43,16 +43,16 @@ Object ^ BitFlipAutomationNameConverter::Convert(_In_ Object ^ value, TypeName t
|
||||||
|
|
||||||
// remove all the characters except 0 and 1 from the array.
|
// remove all the characters except 0 and 1 from the array.
|
||||||
for (wchar_t bit : binaryDisplay)
|
for (wchar_t bit : binaryDisplay)
|
||||||
|
{
|
||||||
|
if ((bit == ch1) || (bit == ch0))
|
||||||
{
|
{
|
||||||
if ((bit == ch1) || (bit == ch0))
|
updatedBinaryDisplay[binaryLength++] = bit;
|
||||||
{
|
|
||||||
updatedBinaryDisplay[binaryLength++] = bit;
|
|
||||||
}
|
|
||||||
if (binaryLength == 63)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (binaryLength == 63)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return if binaryDisplay is empty
|
// return if binaryDisplay is empty
|
||||||
if (binaryLength == 0)
|
if (binaryLength == 0)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -632,9 +632,9 @@ TEST_METHOD(MultipleDateCalculatorTest)
|
||||||
//// Diff in viewModels[0]
|
//// Diff in viewModels[0]
|
||||||
// SYSTEMTIME date1, date2, resultDate;
|
// SYSTEMTIME date1, date2, resultDate;
|
||||||
///* 01-10-2015 */ date1.wDay = 1; date1.wMonth = 10; date1.wYear = 2015; date1.wDayOfWeek = 4; date1.wHour = 0; date1.wMinute = 0; date1.wSecond = 0;
|
///* 01-10-2015 */ date1.wDay = 1; date1.wMonth = 10; date1.wYear = 2015; date1.wDayOfWeek = 4; date1.wHour = 0; date1.wMinute = 0; date1.wSecond = 0;
|
||||||
///date1.wMilliseconds = 0;
|
/// date1.wMilliseconds = 0;
|
||||||
///* 15-02-2016 */ date2.wDay = 15; date2.wMonth = 2; date2.wYear = 2016; date2.wDayOfWeek = 1; date2.wHour = 0; date2.wMinute = 0; date2.wSecond = 0;
|
///* 15-02-2016 */ date2.wDay = 15; date2.wMonth = 2; date2.wYear = 2016; date2.wDayOfWeek = 1; date2.wHour = 0; date2.wMinute = 0; date2.wSecond = 0;
|
||||||
///date2.wMilliseconds = 0;
|
/// date2.wMilliseconds = 0;
|
||||||
|
|
||||||
// viewModels[0]->FromDate = DateUtils::SystemTimeToDateTime(date1);
|
// viewModels[0]->FromDate = DateUtils::SystemTimeToDateTime(date1);
|
||||||
// viewModels[0]->ToDate = DateUtils::SystemTimeToDateTime(date2);
|
// viewModels[0]->ToDate = DateUtils::SystemTimeToDateTime(date2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue