Mantid
Loading...
Searching...
No Matches
DateTimeValidator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
10#include <memory>
11#include <stdexcept>
12
13namespace Mantid::Kernel {
14
15using namespace DateAndTimeHelpers;
19IValidator_sptr DateTimeValidator::clone() const { return std::make_shared<DateTimeValidator>(*this); }
20
22
27void DateTimeValidator::allowEmpty(const bool &allow) { m_allowedEmpty = allow; }
28
34std::string DateTimeValidator::checkValidity(const std::string &value) const {
35 // simply pass off the work DateAndTime constructor
36 // the DateAndTimeHelpers::stringIsISO8601 does not seem strict enough, it
37 // accepts empty strings & strings of letters!
38 if (m_allowedEmpty && value.empty()) {
39 return "";
40 } else {
41 std::string error;
42 try {
43 Types::Core::DateAndTime timestamp(value);
44 UNUSED_ARG(timestamp);
45 } catch (std::invalid_argument &exc) {
46 error = exc.what();
47 }
48 return error;
49 }
50}
51} // namespace Mantid::Kernel
double value
The value of the point.
Definition FitMW.cpp:51
double error
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition System.h:48
IValidator_sptr clone() const override
Clone the current state.
bool m_allowedEmpty
Allows for an empty string to be accepted as input.
void allowEmpty(const bool &)
Sets the value of the m_allowEmpty variable.
std::string checkValidity(const std::string &value) const override
Checks the value is valid.
DateTimeValidator(bool allowEmpty=false)
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition IValidator.h:26