This repository has been archived by the owner on Apr 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Start Time Business Hours NA.c
49 lines (46 loc) · 2.14 KB
/
Start Time Business Hours NA.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Forumla for the {Start Time Business Hours *}.
* To use, copy the formula ONLY. do not copy this note.
* THIS FIELD DOES NOT EXIST IN PRODUCTION: It is the inner workings of a larger formula.
*
* This formula does 2 things:
* - If {Application Started Processing} + 10 hours (+10GMT) is greater than 0...
* - Add 8 hours, minus the hours from the {application started processing} field.
* ELSE:
* - If {Application Started Processing} is before 8am, change time to 8am.
* - IF {Application Started Processing} is AFTER 6pm, change time to 6pm.
*
*/
// Functioning example:
IF(
HOUR(DATEADD({Application Started Processing}, 10, 'hours')) < 0,
DATEADD({Application Started Processing}, (8 - HOUR({Application Started Processing})), 'hour'),
IF(
HOUR(DATEADD({Application Started Processing}, 10, 'hours')) < 8,
DATEADD({Application Started Processing}, (36480 - ((HOUR(DATEADD({Application Started Processing}, 10, 'hours')) * 60)) - MINUTE({Application Started Processing})), 'minute'),
IF(
HOUR(DATEADD({Application Started Processing}, 10, 'hours')) > 18,
DATEADD({Application Started Processing}, -((HOUR({Application Started Processing}) * 60) + MINUTE({Application Started Processing}) - 1080), 'minute'),
{Application Started Processing}
)
)
)
// reusable version:
// Set {asp} to your start time.
/*
* This example has a field with a start time called 'asp', and the business hours are set by another field called {Open Time} and {close Time}
* {Timezone} is a number, which is +/- 0GMT. For example, set this field to '0' for GMT. Brisbane is '10'. etc.
*/
IF(
HOUR(DATEADD({asp}, {Timezone}, 'hours')) < 0,
DATEADD({asp}, ({Open Time} - HOUR({asp})), 'hour'),
IF(
HOUR(DATEADD({asp}, {Timezone}, 'hours')) < {Open Time},
DATEADD({asp}, (36480 - ((HOUR(DATEADD({asp}, {Timezone}, 'hours')) * 60)) - MINUTE({asp})), 'minute'),
IF(
HOUR(DATEADD(asp, {Timezone}, 'hours')) > {close Time},
DATEADD({asp}, -((HOUR({asp}) * 60) + MINUTE({asp}) - 1080), 'minute'),
{asp}
)
)
)