Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-web
Commits
714923bb
Commit
714923bb
authored
Feb 13, 2017
by
mdsecurity
Browse files
Fixing isOpen() method
parent
52beebe2
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/app/data-provider.service.ts
View file @
714923bb
...
...
@@ -28,26 +28,31 @@ export class DataProviderService {
.
map
(
this
.
extractData
)
.
catch
(
this
.
handleError
);
}
// TODO
// there is a little bit of a hack here that checks if the place is 24Hours
// will remove later as the api changes
private
extractData
(
res
:
Response
):
Place
[]
{
let
parseTime
=
function
(
time
:
string
):
Time
{
const
timeArr
=
time
.
split
(
'
:
'
);
const
hour
=
Number
(
timeArr
[
0
]);
const
minute
=
Number
(
timeArr
[
1
]);
const
second
=
Number
(
timeArr
[
2
]);
return
new
Time
(
hour
,
minute
,
second
);
}
let
places
:
Place
[]
=
[];
let
data
=
res
.
json
();
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
let
main_schedule_times
:
Day
[]
=
[];
for
(
let
e
=
0
;
e
<
data
[
i
].
main_schedule
.
open_times
.
length
;
e
++
)
{
let
jsonDay
=
data
[
i
].
main_schedule
.
open_times
[
e
];
// hack is here
if
(
jsonDay
.
end_time
===
'
00:00:00
'
){
jsonDay
.
end_time
=
'
23:59:59
'
;};
const
day
=
new
Day
(
jsonDay
.
id
,
jsonDay
.
last_modified
,
jsonDay
.
schedule
,
jsonDay
.
start_day
,
new
Time
(
jsonDay
.
start_time
),
parse
Time
(
jsonDay
.
start_time
),
jsonDay
.
end_day
,
new
Time
(
jsonDay
.
end_time
));
parse
Time
(
jsonDay
.
end_time
));
main_schedule_times
.
push
(
Object
.
freeze
(
day
));
}
...
...
@@ -77,5 +82,5 @@ export class DataProviderService {
console
.
error
(
errMsg
);
return
Observable
.
throw
(
errMsg
);
}
}
src/app/place.ts
View file @
714923bb
import
{
Day
}
from
'
./day
'
;
import
{
Time
}
from
'
./time
'
;
export
class
Place
{
main_schedule_times
:
Day
[]
=
[];
special_schedule_times
=
[];
id
:
number
;
last_modified
:
string
;
name
:
string
;
category
:
number
;
location
:
string
;
constructor
(
main_schedule_times
:
Day
[],
special_schedule_times
,
id
:
number
,
last_modified
:
string
,
name
:
string
,
category
:
number
,
location
:
string
)
{
id
:
number
;
last_modified
:
string
;
name
:
string
;
category
:
number
;
location
:
string
;
constructor
(
main_schedule_times
:
Day
[],
special_schedule_times
,
id
:
number
,
last_modified
:
string
,
name
:
string
,
category
:
number
,
location
:
string
)
{
this
.
main_schedule_times
=
main_schedule_times
;
this
.
special_schedule_times
=
special_schedule_times
;
this
.
id
=
id
;
...
...
@@ -17,40 +21,34 @@ export class Place {
this
.
location
=
location
;
}
// This method does NOT work with Special schedules
isOpen
():
boolean
{
isOpen
():
boolean
{
const
currTime
=
new
Date
();
const
inSeconds
=
currTime
.
getHours
()
*
60
*
60
+
currTime
.
getMinutes
()
*
60
+
currTime
.
getSeconds
();
const
today
=
currTime
.
getDay
()
-
1
;
const
openDays
:
Day
[]
=
this
.
onDay
(
today
);
for
(
let
i
=
0
;
i
<
openDays
.
length
;
i
++
){
let
day
=
openDays
[
i
];
if
(
day
.
start_day
===
today
&&
inSeconds
<
day
.
start_time
.
inSeconds
()){
return
true
;
}
if
(
day
.
end_day
===
today
&&
inSeconds
<
day
.
end_time
.
inSeconds
()){
return
true
;
const
inSeconds
=
currTime
.
getHours
()
*
60
*
60
+
currTime
.
getMinutes
()
*
60
+
currTime
.
getSeconds
();
const
dayOfWeek
=
currTime
.
getDay
()
-
1
;
for
(
let
i
=
0
;
i
<
this
.
main_schedule_times
.
length
;
i
++
)
{
const
day
=
this
.
main_schedule_times
[
i
];
if
(
day
.
start_day
===
dayOfWeek
||
day
.
end_day
===
dayOfWeek
+
1
)
{
if
(
day
.
end_time
.
inSeconds
()
>
inSeconds
)
{
return
true
;
}
}
}
return
false
;
}
// returns index(s) Days that have an end day or start day on a an arg day of the week
private
onDay
(
dayOfWeek
:
number
):
Day
[]{
let
days
:
Day
[]
=
[];
openFor
()
{
const
currTime
=
new
Date
();
const
today
=
currTime
.
getDay
()
-
1
;
// const today = currTime.getDay() - 1;
// const openDays: Day[] = this.onDay(today);
// const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds();
// let sumSeconds = 0;
// for (let i = 0; i < openDays.length; i++) {
// let day = openDays[i];
// sumSeconds += day.end_time.inSeconds() - day.end_time.inSeconds();
// }
for
(
let
i
=
0
;
i
<
this
.
main_schedule_times
.
length
;
i
++
){
let
day
=
this
.
main_schedule_times
[
i
];
if
(
day
.
start_day
===
today
){
days
.
push
(
day
);
}
if
(
day
.
end_day
===
today
){
days
.
push
(
day
);
}
}
return
days
;
}
}
src/app/time.ts
View file @
714923bb
...
...
@@ -3,12 +3,10 @@ export class Time {
minute
:
number
;
second
:
number
;
constructor
(
time
:
string
)
{
const
timeArr
=
time
.
split
(
'
:
'
);
this
.
hour
=
Number
(
timeArr
[
0
]);
this
.
minute
=
Number
(
timeArr
[
1
]);
this
.
second
=
Number
(
timeArr
[
2
]);
constructor
(
hour
:
number
,
minute
:
number
,
second
:
number
)
{
this
.
hour
=
hour
||
0
;
this
.
minute
=
minute
||
0
;
this
.
second
=
second
||
0
;
}
isGreater
(
time
:
Time
):
boolean
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment