forked from organicmaps/organicmaps
Rename the rest of OSMTimeRange::parse to OSMTimeRange::FromString. Rename Weekdays to Weekday.
This commit is contained in:
parent
338b51eae6
commit
3e45bcf446
5 changed files with 723 additions and 722 deletions
File diff suppressed because it is too large
Load diff
|
@ -30,11 +30,13 @@
|
|||
|
||||
namespace osmoh
|
||||
{
|
||||
class Time
|
||||
|
||||
|
||||
class Time
|
||||
{
|
||||
public:
|
||||
enum EFlags
|
||||
{
|
||||
public:
|
||||
enum EFlags
|
||||
{
|
||||
eNone = 0,
|
||||
eHours = 1,
|
||||
eMinutes = 2,
|
||||
|
@ -71,16 +73,16 @@ namespace osmoh
|
|||
friend std::ostream & operator << (std::ostream & s, TimeSpan const & span);
|
||||
};
|
||||
|
||||
class Weekdays
|
||||
class Weekday
|
||||
{
|
||||
public:
|
||||
uint8_t weekdays;
|
||||
uint16_t nth;
|
||||
int32_t offset;
|
||||
|
||||
Weekdays() : weekdays(0), nth(0), offset(0) {}
|
||||
Weekday() : weekdays(0), nth(0), offset(0) {}
|
||||
|
||||
friend std::ostream & operator << (std::ostream & s, Weekdays const & w);
|
||||
friend std::ostream & operator << (std::ostream & s, Weekday const & w);
|
||||
};
|
||||
|
||||
class State
|
||||
|
@ -101,7 +103,7 @@ namespace osmoh
|
|||
class TimeRule
|
||||
{
|
||||
public:
|
||||
std::vector<Weekdays> weekdays;
|
||||
std::vector<Weekday> weekdays;
|
||||
std::vector<TimeSpan> timespan;
|
||||
State state;
|
||||
uint8_t int_flags = 0;
|
||||
|
|
|
@ -5,112 +5,112 @@
|
|||
UNIT_TEST(OpeningHours_Parse)
|
||||
{
|
||||
{
|
||||
OSMTimeRange oh("06:00-09:00/03");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("06:00-09:00/03");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("06:00-07:00/03");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("06:00-07:00/03");
|
||||
TEST(oh.IsValid() == false, ());
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("sunrise-sunset");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("sunrise-sunset");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Apr-Sep Su [1,3] 14:30-17:00");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Apr-Sep Su [1,3] 14:30-17:00");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("06:00+");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("06:00+");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("06:00-07:00+");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("06:00-07:00+");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("24/7");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("24/7");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("06:13-15:00");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("06:13-15:00");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Mo-Su 08:00-23:00");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Mo-Su 08:00-23:00");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("(sunrise+02:00)-(sunset-04:12)");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("(sunrise+02:00)-(sunset-04:12)");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Mo-Sa; PH off");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Mo-Sa; PH off");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Jan-Mar 07:00-19:00;Apr-Sep 07:00-22:00;Oct-Dec 07:00-19:00");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Jan-Mar 07:00-19:00;Apr-Sep 07:00-22:00;Oct-Dec 07:00-19:00");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Mo closed");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Mo closed");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("06:00-23:00 open \"Dining in\"");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("06:00-23:00 open \"Dining in\"");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("06:00-23:00 open \"Dining in\" || 00:00-24:00 open \"Drive-through\"");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("06:00-23:00 open \"Dining in\" || 00:00-24:00 open \"Drive-through\"");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Tu-Th 20:00-03:00 open \"Club and bar\"; Fr-Sa 20:00-04:00 open \"Club and bar\" || Su-Mo 18:00-02:00 open \"bar\" || Tu-Th 18:00-03:00 open \"bar\" || Fr-Sa 18:00-04:00 open \"bar\"");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Tu-Th 20:00-03:00 open \"Club and bar\"; Fr-Sa 20:00-04:00 open \"Club and bar\" || Su-Mo 18:00-02:00 open \"bar\" || Tu-Th 18:00-03:00 open \"bar\" || Fr-Sa 18:00-04:00 open \"bar\"");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("09:00-21:00 \"call us\"");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("09:00-21:00 \"call us\"");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("10:00-13:30,17:00-20:30");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("10:00-13:30,17:00-20:30");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Apr-Sep: Mo-Fr 09:00-13:00,14:00-18:00; Apr-Sep: Sa 10:00-13:00");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Apr-Sep: Mo-Fr 09:00-13:00,14:00-18:00; Apr-Sep: Sa 10:00-13:00");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Mo,We,Th,Fr 12:00-18:00; Sa-Su 12:00-17:00");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Mo,We,Th,Fr 12:00-18:00; Sa-Su 12:00-17:00");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Su-Th 11:00-03:00, Fr-Sa 11:00-05:00");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Su-Th 11:00-03:00, Fr-Sa 11:00-05:00");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Mo-We 17:00-01:00, Th,Fr 15:00-01:00; PH off");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Mo-We 17:00-01:00, Th,Fr 15:00-01:00; PH off");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
/* test disabled because we go out from DSL definition in some cases */
|
||||
// OSMTimeRange oh("Tu-Su, Ph 10:00-18:00");
|
||||
// OSMTimeRange oh = OSMTimeRange::FromString("Tu-Su, Ph 10:00-18:00");
|
||||
// TEST(oh.IsValid() == false, ("Broken parser"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Tu-Su 10:00-18:00, Mo 12:00-17:00");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Tu-Su 10:00-18:00, Mo 12:00-17:00");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("06:00-07:00/21:03");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("06:00-07:00/21:03");
|
||||
TEST(oh.IsValid() == false, ("Period can't be large then interval"));
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("sunset-sunrise");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("sunset-sunrise");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
}
|
||||
}
|
||||
|
@ -118,33 +118,33 @@ UNIT_TEST(OpeningHours_Parse)
|
|||
UNIT_TEST(OpeningHours_TimeHit)
|
||||
{
|
||||
{
|
||||
OSMTimeRange oh("06:13-15:00; 16:30+");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("06:13-15:00; 16:30+");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
TEST(oh("12-12-2013 7:00").IsOpen(), ());
|
||||
TEST(oh("12-12-2013 16:00").IsClosed(), ());
|
||||
TEST(oh("12-12-2013 20:00").IsOpen(), ());
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("We-Sa; Mo[1,3] closed; Su[-1,-2] closed; Fr[2] open; Fr[-2], Fr open; Su[-2] -2 days");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("We-Sa; Mo[1,3] closed; Su[-1,-2] closed; Fr[2] open; Fr[-2], Fr open; Su[-2] -2 days");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
TEST(oh("20-03-2015 18:00").IsOpen(), ());
|
||||
TEST(oh("17-03-2015 18:00").IsClosed(), ());
|
||||
}
|
||||
|
||||
{
|
||||
OSMTimeRange oh("We-Fr; Mo[1,3] closed; Su[-1,-2] closed");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("We-Fr; Mo[1,3] closed; Su[-1,-2] closed");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
TEST(oh("20-03-2015 18:00").IsOpen(), ());
|
||||
TEST(oh("17-03-2015 18:00").IsClosed(), ());
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("We-Fr; Mo[1,3] +1 day closed; Su[-1,-2] -3 days closed");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("We-Fr; Mo[1,3] +1 day closed; Su[-1,-2] -3 days closed");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
TEST(oh("20-03-2015 18:00").IsOpen(), ());
|
||||
TEST(oh("17-03-2015 18:00").IsClosed(), ());
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Mo-Su 14:30-17:00; Mo[1] closed; Su[-1] closed");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Mo-Su 14:30-17:00; Mo[1] closed; Su[-1] closed");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
TEST(oh("09-03-2015 16:00").IsOpen(), ());
|
||||
TEST(oh("02-03-2015 16:00").IsClosed(), ());
|
||||
|
@ -152,7 +152,7 @@ UNIT_TEST(OpeningHours_TimeHit)
|
|||
TEST(oh("29-03-2015 16:00").IsClosed(), ());
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("PH,Tu-Su 10:00-18:00; Sa[1] 10:00-18:00 open \"Eintritt ins gesamte Haus frei\"; Jan 1,Dec 24,Dec 25,easter -2 days: closed");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("PH,Tu-Su 10:00-18:00; Sa[1] 10:00-18:00 open \"Eintritt ins gesamte Haus frei\"; Jan 1,Dec 24,Dec 25,easter -2 days: closed");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
TEST(oh("03-03-2015 16:00").IsOpen(), ());
|
||||
TEST(oh.Comment().empty(), ());
|
||||
|
@ -160,7 +160,7 @@ UNIT_TEST(OpeningHours_TimeHit)
|
|||
TEST(oh.Comment().empty() == false, ());
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("Mo-Su 11:00+; Mo [1,3] off");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("Mo-Su 11:00+; Mo [1,3] off");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
TEST(oh("04-03-2015 16:00").IsOpen(), ());
|
||||
TEST(oh("09-03-2015 16:00").IsOpen(), ());
|
||||
|
@ -168,11 +168,9 @@ UNIT_TEST(OpeningHours_TimeHit)
|
|||
TEST(oh("16-03-2015 16:00").IsClosed(), ());
|
||||
}
|
||||
{
|
||||
OSMTimeRange oh("08:00-16:00 open, 16:00-03:00 open \"public room\"");
|
||||
OSMTimeRange oh = OSMTimeRange::FromString("08:00-16:00 open, 16:00-03:00 open \"public room\"");
|
||||
TEST(oh.IsValid(), ("Incorrect schedule string"));
|
||||
TEST(oh("01-03-2015 20:00").IsOpen(), ());
|
||||
TEST(oh("01-03-2015 20:00").Comment() == "public room", ());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ inline string DebugPrint(EPlaceState state)
|
|||
|
||||
inline EPlaceState PlaceStateCheck(string const & openingHours, time_t timestamp)
|
||||
{
|
||||
OSMTimeRange oh(openingHours);
|
||||
OSMTimeRange oh = OSMTimeRange::FromString(openingHours);
|
||||
auto future = system_clock::from_time_t(timestamp);
|
||||
future += minutes(15);
|
||||
size_t nowState = oh(timestamp).IsOpen() ? 0 : 1;
|
||||
|
|
|
@ -41,7 +41,7 @@ void ProcessMetadata(FeatureType const & ft, Result::Metadata & meta)
|
|||
// Lib opening_hours is not built for Linux since stdlib doesn't have required functions.
|
||||
string const openHours = src.Get(feature::Metadata::FMD_OPEN_HOURS);
|
||||
if (!openHours.empty())
|
||||
meta.m_isClosed = OSMTimeRange(openHours)(time(nullptr)).IsClosed();
|
||||
meta.m_isClosed = OSMTimeRange::FromString(openHours)(time(nullptr)).IsClosed();
|
||||
#endif
|
||||
|
||||
meta.m_stars = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue