mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
ConvertTime: AlwaysTime, DayEnd
git-svn-id: svn://ultimatepp.org/upp/trunk@6610 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
87a223a54d
commit
697d44360d
4 changed files with 38 additions and 6 deletions
|
|
@ -212,9 +212,11 @@ Value StrDblValue(const char *s)
|
|||
return (double)Null;
|
||||
}
|
||||
|
||||
Value Scan(dword qtype, const String& text, const Value& def) {
|
||||
Value Scan(dword qtype, const String& text, const Value& def, bool *hastime) {
|
||||
Date date;
|
||||
const char *s;
|
||||
if(hastime)
|
||||
*hastime = false;
|
||||
switch(qtype) {
|
||||
case INT64_V:
|
||||
case INT_V:
|
||||
|
|
@ -245,6 +247,8 @@ Value Scan(dword qtype, const String& text, const Value& def) {
|
|||
tm.second = d.second;
|
||||
if(p.IsEof())
|
||||
return tm;
|
||||
if(hastime)
|
||||
*hastime = true;
|
||||
int q = p.ReadInt();
|
||||
if(q < 0 || q > 23)
|
||||
throw CParser::Error("");
|
||||
|
|
@ -423,6 +427,8 @@ int ConvertDate::Filter(int chr) const {
|
|||
ConvertTime::ConvertTime(Time minval, Time maxval, bool notnull)
|
||||
: minval(minval), maxval(maxval), notnull(notnull), seconds(true) {
|
||||
defaultval = Null;
|
||||
timealways = false;
|
||||
dayend = false;
|
||||
}
|
||||
|
||||
ConvertTime::~ConvertTime()
|
||||
|
|
@ -431,10 +437,17 @@ ConvertTime::~ConvertTime()
|
|||
|
||||
Value ConvertTime::Scan(const Value& text) const
|
||||
{
|
||||
Value v = UPP::Scan(TIME_V, text);
|
||||
bool hastime;
|
||||
Value v = UPP::Scan(TIME_V, text, defaultval, &hastime);
|
||||
if(IsError(v)) return v;
|
||||
if(IsNull(v)) return notnull ? NotNullError() : v;
|
||||
Time m = v;
|
||||
if(!hastime && dayend) {
|
||||
m.hour = 23;
|
||||
m.minute = 59;
|
||||
m.second = 59;
|
||||
v = m;
|
||||
}
|
||||
if(m >= minval && m <= maxval) return v;
|
||||
return ErrorValue(t_("Time must be between ") + UPP::Format(minval) + t_("range\v and ") + UPP::Format(maxval) + ".");
|
||||
}
|
||||
|
|
@ -452,8 +465,9 @@ Value ConvertTime::Format(const Value& q) const
|
|||
{
|
||||
if(IsVoid(q) || q.IsNull())
|
||||
return String();
|
||||
else if(q.GetType() == TIME_V)
|
||||
return UPP::Format(Time(q), seconds);
|
||||
else
|
||||
if(q.GetType() == TIME_V || timealways)
|
||||
return ToTime((Date)q) != (Time)q || timealways ? UPP::Format(Time(q), seconds) : UPP::Format(Date(q));
|
||||
else
|
||||
return Convert::Format(q);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,6 +157,8 @@ protected:
|
|||
Time minval, maxval, defaultval;
|
||||
bool notnull;
|
||||
bool seconds;
|
||||
bool timealways;
|
||||
bool dayend;
|
||||
|
||||
public:
|
||||
ConvertTime& MinMax(Time _min, Time _max) { minval = _min; maxval = _max; return *this; }
|
||||
|
|
@ -166,11 +168,15 @@ public:
|
|||
ConvertTime& NoNotNull() { return NotNull(false); }
|
||||
ConvertTime& Seconds(bool b = true) { seconds = b; return *this; }
|
||||
ConvertTime& NoSeconds() { return Seconds(false); }
|
||||
ConvertTime& TimeAlways(bool b = true) { timealways = b; return *this; }
|
||||
ConvertTime& DayEnd(bool b = true) { dayend = b; return *this; }
|
||||
ConvertTime& Default(Time d) { defaultval = d; return *this; }
|
||||
Time GetMin() const { return minval; }
|
||||
Time GetMax() const { return maxval; }
|
||||
bool IsNotNull() const { return notnull; }
|
||||
bool IsSeconds() const { return seconds; }
|
||||
bool IsTimeAlways() const { return timealways; }
|
||||
bool IsDayEnd() const { return dayend; }
|
||||
|
||||
ConvertTime(Time minval = ToTime(Date::Low()), Time maxval = ToTime(Date::High()), bool notnull = false);
|
||||
virtual ~ConvertTime();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Value Scan(dword stdtype, const String& text, const Value& def = Null);
|
||||
Value Scan(dword stdtype, const String& text, const Value& def = Null, bool *hastime = NULL);
|
||||
|
||||
inline const String& Nvl(const String& a, const String& b) { return IsNull(a) ? b : a; }
|
||||
inline int Nvl(int a, int b) { return IsNull(a) ? b : a; }
|
||||
|
|
|
|||
|
|
@ -420,6 +420,18 @@ ll]()&]
|
|||
otNull](false).&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:ConvertTime`:`:TimeAlways`(bool`):%- [_^ConvertTime^ ConvertTime][@(0.0.255) `&]_[* Ti
|
||||
meAlways]([@(0.0.255) bool]_[*@3 b]_`=_[@(0.0.255) true])&]
|
||||
[s2; If active, Format always shows time, even if the Value is Date
|
||||
or is at midnight.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:ConvertTime`:`:DayEnd`(bool`):%- [_^ConvertTime^ ConvertTime][@(0.0.255) `&]_[* DayEnd
|
||||
]([@(0.0.255) bool]_[*@3 b]_`=_[@(0.0.255) true])&]
|
||||
[s2; If active, when Scan encounters date without time, it sets the
|
||||
time to 23:59:59.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:ConvertTime`:`:GetMin`(`)const:%- [_^Time^ Time]_[* GetMin]()_[@(0.0.255) const]&]
|
||||
[s7; [*/ Return value]-|Lower limit.&]
|
||||
[s3; &]
|
||||
|
|
@ -585,4 +597,4 @@ ll, Null, true)]&]
|
|||
[s2; [C^topic`:`/`/Core`/src`/Convert`$en`-us`#ConvertString`:`:class^1 ConvertString][C1 (
|
||||
INT`_MAX, true)]&]
|
||||
[s3;%- &]
|
||||
[s0; ]
|
||||
[s0; ]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue