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
3346e09a
Commit
3346e09a
authored
Apr 25, 2017
by
mdsecurity
Browse files
openFor and isOpen methods now take into account special schedules
parent
d4b3f299
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/app/data-provider.service.ts
View file @
3346e09a
...
...
@@ -88,27 +88,27 @@ export class DataProviderService {
}
for
(
let
e
=
0
;
e
<
data
[
i
].
special_schedules
.
length
;
e
++
)
{
const
jsonSchedule
=
data
[
i
].
special_schedules
[
e
];
let
open_times
:
Day
[]
=
[];
for
(
let
f
=
0
;
f
<
jsonSchedule
.
open_times
.
length
;
f
++
){
let
open_times
:
Day
[]
=
[];
for
(
let
f
=
0
;
f
<
jsonSchedule
.
open_times
.
length
;
f
++
)
{
let
jsonDay
=
jsonSchedule
.
open_times
[
f
];
const
day
=
new
Day
(
jsonDay
.
id
,
jsonDay
.
last_modified
,
jsonDay
.
schedule
,
jsonDay
.
start_day
,
parseTime
(
jsonDay
.
start_time
),
jsonDay
.
end_day
,
parseTime
(
jsonDay
.
end_time
));
jsonDay
.
id
,
jsonDay
.
last_modified
,
jsonDay
.
schedule
,
jsonDay
.
start_day
,
parseTime
(
jsonDay
.
start_time
),
jsonDay
.
end_day
,
parseTime
(
jsonDay
.
end_time
));
open_times
.
push
(
Object
.
freeze
(
day
));
}
const
schedule
=
new
SpecialSchedule
(
jsonSchedule
.
valid_start
,
jsonSchedule
.
valid_end
,
open_times
);
const
schedule
=
new
SpecialSchedule
(
jsonSchedule
.
valid_start
,
jsonSchedule
.
valid_end
,
open_times
);
special_schedules
.
push
(
Object
.
freeze
(
schedule
));
}
console
.
log
(
special_schedules
);
places
.
push
(
new
Place
(
main_schedule_times
,
[]
,
special_schedules
,
data
[
i
].
id
,
data
[
i
].
last_modified
,
data
[
i
].
name
,
...
...
src/app/place.ts
View file @
3346e09a
...
...
@@ -10,7 +10,7 @@ export class Place {
name
:
string
;
category
:
number
;
location
:
string
;
constructor
(
main_schedule_times
?:
Day
[],
special_schedules
?:
SpecialSchedule
[],
id
?:
number
,
last_modified
?:
string
,
constructor
(
main_schedule_times
?:
Day
[],
special_schedules
?:
SpecialSchedule
[],
id
?:
number
,
last_modified
?:
string
,
name
?:
string
,
category
?:
number
,
location
?:
string
)
{
this
.
main_schedule_times
=
main_schedule_times
||
[];
...
...
@@ -26,8 +26,14 @@ export class Place {
const
currTime
=
new
Date
();
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
useSpecialSchedule
=
this
.
useSpecial
();
let
schedule
;
if
(
useSpecialSchedule
===
-
1
){
schedule
=
this
.
main_schedule_times
;
}
else
{
schedule
=
this
.
special_schedules
[
useSpecialSchedule
].
openTimes
;
}
for
(
let
i
=
0
;
i
<
schedule
.
length
;
i
++
)
{
const
day
=
this
.
main_schedule_times
[
i
];
// change the order of if statements at some point
if
(
day
.
start_day
!==
day
.
end_day
)
{
...
...
@@ -76,6 +82,21 @@ export class Place {
return
timeTilClose
;
}
}
useSpecial
():
number
{
const
todaysDate
=
new
Date
();
for
(
let
i
=
0
;
i
<
this
.
special_schedules
.
length
;
i
++
)
{
let
parsedStart
=
this
.
special_schedules
[
i
].
validStart
.
split
(
'
-
'
);
let
parsedEnd
=
this
.
special_schedules
[
i
].
validEnd
.
split
(
'
-
'
);
if
(
todaysDate
.
getFullYear
()
>=
Number
(
parsedStart
[
0
])
&&
todaysDate
.
getFullYear
()
<=
Number
(
parsedEnd
[
0
]))
{
if
(
todaysDate
.
getMonth
()
>=
Number
(
parsedStart
[
1
])
&&
todaysDate
.
getMonth
()
<=
Number
(
parsedEnd
[
1
]))
{
if
(
todaysDate
.
getDate
()
>=
Number
(
parsedStart
[
2
])
&&
todaysDate
.
getDate
()
<=
Number
(
parsedEnd
[
2
]))
{
return
i
;
}
}
}
}
return
-
1
;
}
}
// useSpecial():
src/app/special-schedule.ts
View file @
3346e09a
...
...
@@ -3,13 +3,13 @@ import { Time } from './time';
export
class
SpecialSchedule
{
open
_t
imes
:
Day
[];
valid
_s
tart
:
string
;
valid
_e
nd
:
string
;
open
T
imes
:
Day
[];
valid
S
tart
:
string
;
valid
E
nd
:
string
;
constructor
(
valid_start
:
string
,
valid_end
:
string
,
open_times
?:
Day
[]){
this
.
open
_t
imes
=
open_times
||
[];
this
.
valid
_e
nd
=
valid_end
;
this
.
valid
_s
tart
=
valid_start
;
this
.
open
T
imes
=
open_times
||
[];
this
.
valid
E
nd
=
valid_end
;
this
.
valid
S
tart
=
valid_start
;
}
}
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