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 +
10
11#include <memory>
12#include <stdexcept>
13
14namespace Mantid::Kernel {
15
16using namespace DateAndTimeHelpers;
20IValidator_sptr DateTimeValidator::clone() const { return std::make_shared<DateTimeValidator>(*this); }
21
23
28void DateTimeValidator::allowEmpty(const bool &allow) { m_allowedEmpty = allow; }
29
35std::string DateTimeValidator::checkValidity(const std::string &value) const {
36 // simply pass off the work DateAndTime constructor
37 // the DateAndTimeHelpers::stringIsISO8601 does not seem strict enough, it
38 // accepts empty strings & strings of letters!
39 if (m_allowedEmpty && value.empty()) {
40 return "";
41 } else {
42 std::string error;
43 try {
44 Types::Core::DateAndTime timestamp(value);
45 UNUSED_ARG(timestamp);
46 } catch (std::invalid_argument &exc) {
47 error = exc.what();
48 }
49 return error;
50 }
51}
52} // namespace Mantid::Kernel
double value
The value of the point.
Definition: FitMW.cpp:51
double error
Definition: IndexPeaks.cpp:133
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
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.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26