fullcalendar business hours with validity period - fullcalendar

I would like my calendar to only allow the user to create new events during business hours. The catch is that the business hours are not the same each week, they depend on the date.
My table with the business hours looks like this:
+-----+-----------+----------+------------+------------+
| day | startTime | endTime | firstDate | lastDate |
+-----+-----------+----------+------------+------------+
| 6 | 08:00:00 | 12:30:00 | 2021-12-20 | NULL |
| 6 | 13:00:00 | 16:30:00 | 2021-12-20 | NULL |
| 2 | 08:00:00 | 17:00:00 | 2021-12-27 | 2021-12-27 |
| 4 | 08:00:00 | 17:00:00 | 2021-12-29 | 2021-12-29 |
+-----+-----------+----------+------------+------------+
The business hours in FullCalendar don't have an option to specify validity periods.
I have been looking at using background events but don't quite understand how to achieve the desired result that way.
How can I limit new events to specific times for each day of the week where these times vary each week?

This gets us recurring background events:
{
startTime: '08:00:00',
endTime: '12:30:00',
daysOfWeek: '6',
startRecur: '2021-12-20',
rendering: 'background',
groupId: 1
},
{
startTime: '13:00:00',
endTime: '16:30:00',
daysOfWeek: '6',
startRecur: '2021-12-20',
rendering: 'background',
groupId: 1
}
For more information on recurring events see https://fullcalendar.io/docs/recurring-events

Related

SQLite Turning a YYYY-MM-DD format into SUN/MON/TUE/WED/THU/FRI/SAT

I have a set of 10 dates in the format YYYY-MM-DD (shown below). But I want to change these number format dates into either Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday through SQLite.
How function would I have to use to convert this from a numeric date to a day of the week date?
1992-08-14
1992-05-01
1992-04-01
1993-05-03
1993-10-17
1994-03-05
1993-10-17
1994-01-02
1994-11-15
By STRFTIME('%w', datecolumn) you get the day of the week of a date as a string: '0' for Sunday, '1' for Monday, ..., '6' for Saturday
Use it like this:
SELECT
CASE STRFTIME('%w', datecolumn)
WHEN '0' THEN 'SUN'
WHEN '1' THEN 'MON'
WHEN '2' THEN 'TUE'
WHEN '3' THEN 'WED'
WHEN '4' THEN 'THU'
WHEN '5' THEN 'FRI'
WHEN '6' THEN 'SAT'
END day,
COUNT(*) count
FROM tablename
GROUP BY STRFTIME('%w', datecolumn)
See the demo.
Results:
| day | count |
| --- | ----- |
| SUN | 3 |
| MON | 1 |
| TUE | 1 |
| WED | 1 |
| FRI | 2 |
| SAT | 1 |

Teradata - calculate difference between two dates from different row number

I want to move my excel calculation to Teradata but not sure how to do it. In excel is rather easy and I use simple if to give me DIFF =IF(A2=A3, (C2-B3) * 24, "")
NO T_DATE L_DATE DIFF
AAA 10/08/2019 17:02:00 10/08/2019 20:35:00 5.83
AAA 10/08/2019 14:45:00 10/08/2019 15:10:00 11.78
AAA 10/08/2019 03:23:00 10/08/2019 10:25:00 17.32
AAA 09/08/2019 17:06:00 10/08/2019 01:11:00 25.70
AAA 08/08/2019 23:29:00 09/08/2019 10:27:00
BBB 08/08/2019 09:34:00 08/08/2019 21:19:00 22.23
BBB 07/08/2019 23:05:00 08/08/2019 06:09:00 18.03
BBB 07/08/2019 12:07:00 07/08/2019 20:25:00 22.32
BBB 06/08/2019 22:06:00 07/08/2019 08:53:00 22.77
BBB 06/08/2019 10:07:00 06/08/2019 19:44:00
Is there a way of doing it in Teradata? I want to have again the difference in hours between L_DATE and T_DATE for each NO.
You can use window functions to achieve this. It's important to note that when you subtract two dates or timestamps (in this case) you will be returned in INTERVAL type so you will need to specify what type of INTERVAL you want as well as it's size (SECOND, MINUTE, HOUR, DAY, etc)..
CREATE MULTISET VOLATILE TABLE yourtable(
ID VARCHAR(3)
,T_DATE TIMESTAMP(0)
,L_DATE TIMESTAMP(0)
,DIFF NUMERIC(6,2)
) PRIMARY INDEX (ID) ON COMMIT PRESERVE ROWS;
INSERT INTO yourtable(ID,T_DATE,L_DATE,DIFF) VALUES ('AAA','2019-10-08 17:02:00','2019-10-08 20:35:00',5.83);
INSERT INTO yourtable(ID,T_DATE,L_DATE,DIFF) VALUES ('AAA','2019-10-08 14:45:00','2019-10-08 15:10:00',11.78);
INSERT INTO yourtable(ID,T_DATE,L_DATE,DIFF) VALUES ('AAA','2019-10-08 03:23:00','2019-10-08 10:25:00',17.32);
INSERT INTO yourtable(ID,T_DATE,L_DATE,DIFF) VALUES ('AAA','2019-09-08 17:06:00','2019-10-08 01:11:00',25.70);
INSERT INTO yourtable(ID,T_DATE,L_DATE,DIFF) VALUES ('AAA','2019-08-08 23:29:00','2019-09-08 10:27:00',NULL);
INSERT INTO yourtable(ID,T_DATE,L_DATE,DIFF) VALUES ('BBB','2019-08-08 09:34:00','2019-08-08 21:19:00',22.23);
INSERT INTO yourtable(ID,T_DATE,L_DATE,DIFF) VALUES ('BBB','2019-07-08 23:05:00','2019-08-08 06:09:00',18.03);
INSERT INTO yourtable(ID,T_DATE,L_DATE,DIFF) VALUES ('BBB','2019-07-08 12:07:00','2019-07-08 20:25:00',22.32);
INSERT INTO yourtable(ID,T_DATE,L_DATE,DIFF) VALUES ('BBB','2019-06-08 22:06:00','2019-07-08 08:53:00',22.77);
INSERT INTO yourtable(ID,T_DATE,L_DATE,DIFF) VALUES ('BBB','2019-06-08 10:07:00','2019-06-08 19:44:00',NULL);
SELECT yourtable.*,
CAST(((LEAD(T_DATE) OVER (PARTITION BY ID ORDER BY T_DATE) - L_DATE) HOUR(4)) AS INTEGER)
FROM yourtable;
+-----+---------------------+---------------------+--------+-------------------------------------------+
| ID | T_DATE | L_DATE | DIFF | (LEAD (<value expression>) - L_DATE) HOUR |
+-----+---------------------+---------------------+--------+-------------------------------------------+
| AAA | 2019-08-08 23:29:00 | 2019-09-08 10:27:00 | <null> | 7 |
| AAA | 2019-09-08 17:06:00 | 2019-10-08 01:11:00 | 25.70 | 2 |
| AAA | 2019-10-08 03:23:00 | 2019-10-08 10:25:00 | 17.32 | 4 |
| AAA | 2019-10-08 14:45:00 | 2019-10-08 15:10:00 | 11.78 | 2 |
| AAA | 2019-10-08 17:02:00 | 2019-10-08 20:35:00 | 5.83 | <null> |
| BBB | 2019-06-08 10:07:00 | 2019-06-08 19:44:00 | <null> | 3 |
| BBB | 2019-06-08 22:06:00 | 2019-07-08 08:53:00 | 22.77 | 4 |
| BBB | 2019-07-08 12:07:00 | 2019-07-08 20:25:00 | 22.32 | 3 |
| BBB | 2019-07-08 23:05:00 | 2019-08-08 06:09:00 | 18.03 | 3 |
| BBB | 2019-08-08 09:34:00 | 2019-08-08 21:19:00 | 22.23 | <null> |
+-----+---------------------+---------------------+--------+-------------------------------------------+
The reason this looks so ugly is because you are trying to compare (subtract) values in two different records. In a database there is no relationship between one record and another. There is no ordering. They live independently of one another. This is radically different than excel where rows (records) have order (a row number).
We use the Window Function LEAD() to establish a group of records as being in a group (a partition) using the PARTITION BY clause, and we give that partition an ordering with the ORDER BY clause. Then we use that LEAD() to say "The very next T_DATE in this ordered partition for this record".
Then we do our date math and subtract the two timestamps. We specify that we want an INTERVAL of type HOUR(4) back. This will hold up to 9999 hours and it will error if it goes over 9999 hours.
Lastly we cast that thing to integer so you can do math on it. You do not, however, have to do the casting if you don't want. I added it because often times we want to add hours together and whatnot.
If you are working on an older version of Teradata that doesn't have the LEAD() function (it's a newer addition) you can use MAX() or MIN() and some extra syntax in your windowing definition to explicitely say "Just the next record's T_DATE" like:
MAX(T_DATE) OVER (PARTITION BY ID ORDER BY T_DATE ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING)

Strip the time part from data and calculate time difference between consecutive rows using R

I have an excel file which has a column 'Time' which represents the time. The data type of this column is POSIXct. When I load the excel file in R, some random date part gets appended to the time and so I want to delete this random dates appended, retain only the time part and then calculate the difference between consecutive rows based on grouping Emp_Id and Date columns where I need to see how much was the difference in the clock in and clock out time each day for each employee.
This is how my data looks like when loaded in R with random date getting added.
| Emp_Id | Date | Time | Time_Event |
|--------|:---------:|---------------------:|------------|
| 95 | 3/14/2019 | 1899-12-31 10:47:12 | Clock-In |
| 95 | 3/12/2019 | 1899-12-31 10:51:12 | Clock-In |
| 95 | 3/11/2019 | 1899-12-31 8:15:16 | Clock-Out |
| 95 | 3/12/2019 | 1899-12-31 8:10:07 | Clock-Out |
| 95 | 3/11/2019 | 1899-12-31 10:41:51 | Clock-In |
| 19 | 3/14/2019 | 1899-12-31 6:02:23 | Clock-Out |
| 19 | 3/18/2019 | 1899-12-31 5:44:23 | Clock-In |
| 19 | 3/12/2019 | 1899-12-31 6:05:15 | Clock-Out |
| 19 | 3/12/2019 | 1899-12-31 5:45:57 | Clock-In |
| 19 | 3/14/2019 | 1899-12-31 5:29:32 | Clock-In |
To make it easy, the data will be:
Emp_Id <- as.numeric(c("95", "95", "95", "95", "95", "19", "19", "19", "19", "19"))
Date <- c("3/14/2019","3/12/2019","3/11/2019", "3/12/2019","3/11/2019","3/14/2019","3/18/2019","3/12/2019","3/12/2019","3/14/2019")
Time <- as.POSIXct(c("1899-12-31 10:47:12", "1899-12-31 10:51:12", "1899-12-31 8:15:16","1899-12-31 8:10:07", "1899-12-31 10:41:51",
"1899-12-31 6:02:23", "1899-12-31 5:44:23", "1899-12-31 6:05:15", "1899-12-31 5:45:57","1899-12-31 5:29:32"))
Time_Event <- c("Clock-In","Clock-In","Clock-Out","Clock-Out","Clock-In","Clock-Out","Clock-In","Clock-Out","Clock-In","Clock-In")
df2 <- data.frame(Emp_Id,Date,Time,Time_Event, stringsAsFactors = F)
df2$Date= as.Date(df2$Date, format = "%m/%d/%Y")
Using df$Time <- format(strptime(df$Time, "%Y-%m-%d %H:%M:%S"), "%H:%M:%S") strips the time part but converts the data type to character. Since I need to calculate the difference, I cannot do this on character data type. I have been through this link How to calculate time difference in consecutive rows, but this doesn't help.
I have tried the below code but I get error because of the character data type
df2 <- df2 %>%
arrange(df2$Emp_Id, df2$Date, df2$Time) %>%
group_by(df2$Emp_Id,df2$Date) %>%
mutate(diff = format(strptime(df2$Time, "%Y-%m-%d %H:%M:%S"),"%H:%M:%S")-
lag(format(strptime(df2$Time, "%Y-%m-%d %H:%M:%S"),"%H:%M:%S"),
default = format(strptime(df2$Time, "%Y-%m-%d %H:%M:%S"),"%H:%M:%S")[1]),
diff_secs = as.numeric(diff, units = 'secs'))
How can I achieve the final output to look like:
| Emp_Id | Date | Time | Time_Event | Diff(In seconds) |
|--------|:---------:|---------:|------------|------------------|
| 19 | 3/12/2019 | 5:45:57 | Clock-In | NA |
| 19 | 3/12/2019 | 18:05:15 | Clock-Out | 44358 |
| 19 | 3/14/2019 | 5:29:32 | Clock-In | NA |
| 19 | 3/14/2019 | 18:02:23 | Clock-Out | 45171 |
| 19 | 3/18/2019 | 17:44:23 | Clock-In | NA |
| 95 | 3/11/2019 | 10:41:51 | Clock-In | NA |
| 95 | 3/11/2019 | 20:15:16 | Clock-Out | 33844 |
| 95 | 3/12/2019 | 10:51:12 | Clock-In | NA |
| 95 | 3/12/2019 | 20:10:07 | Clock-Out | 33535 |
| 95 | 3/14/2019 | 10:47:12 | Clock-In | NA |
library(dplyr)
library(tidyr)
df2 %>%
arrange(Emp_Id, Date, Time) %>%
group_by(Emp_Id, Date) %>%
mutate(Diff = as.numeric(Time - lag(Time), units = "secs")) %>%
ungroup()
We can use
library(data.table)
setDT(df1)[order(Emp_Id, Date, Time), Date :=
as.numeric(Time - shift(Time)), .(Emp_Id, Date)]

Time Conversion Only (Hour and Minute) [duplicate]

This question already has answers here:
keep only hour: minute:second from a "POSIXlt" "POSIXt" object
(1 answer)
how do you pick the hour, minute and second from the posixct formated datetime in R
(2 answers)
Date time conversion and extract only time
(6 answers)
Closed 3 years ago.
I have observation data which only give hour and minute mark, the data looks like this:
- date | time | value
- 2019-01-01 | 00:00 | 14
- 2019-01-01 | 00:30 | 23
- 2019-01-01 | 01:00 | 32
- 2019-01-01 | 01:30 | 41
- 2019-01-02 | 00:00 | 41
- 2019-01-02 | 00:30 | 32
- 2019-01-02 | 01:00 | 23
- 2019-01-02 | 01:30 | 14
- ....
I successfully convert the date into the data format using
data$date <- as.Date(data$date, "%Y/%m/%d")
but when i try to convert the time to its format, i encounter problem, I tried using this:
data$time <- strptime(data$time, "%H:%M")
this give me the result of time with current date: "2019-03-14 00:00:00". which is not what i'm looking for and the date is false
I also tried using:
trydata$jam <- timestamp(trydata$jam, "%H:%M")
this give me the result:
%H:%M00:00 ------##
What is the best way to do this? I also want to extract the data in certain duration of time (like from 10:00 to 13:00)
Thank You

why datetime showed not like in the DB?

I've in the database the following lines
id | date_order | name | origin
----+---------------------+----------+---------
38 | 2016-05-10 14:00:00 | OT/00024 | GI/00005:
39 | 2016-05-26 14:00:00 | OT/00025 | GI/00005:
40 | 2016-06-11 14:00:00 | OT/00026 | GI/00005:
41 | 2016-06-27 14:00:00 | OT/00027 | GI/00005:
42 | 2016-07-13 14:00:00 | OT/00028 | GI/00005:
but it showed in the views as:
date_order | name | origin
--------------------+----------+-------------
10/05/2016 15:00:00 | OT/00024 | GI/00005:
26/05/2016 15:00:00 | OT/00025 | GI/00005:
11/06/2016 14:00:00 | OT/00026 | GI/00005:
27/06/2016 14:00:00 | OT/00027 | GI/00005:
13/07/2016 15:00:00 | OT/00028 | GI/00005:
I changed Timezone but I still get the difference !
When you store the datetime, you should use context like this:
from openerp.osv import fields
from datetime import datetime
...
my_date = fields.datetime.context_timestamp(cr, uid, datetime.now(), context=context)
The date stored in the database is UTC (GMT-0) timezone. Assume that the person is set with timezone GMT - 5:00, then while storing the value to the database, the date will be added with 5 hrs (exactly 5, not little more or little less) and thus we get the UTC time to store into the database. Now when displaying the same it will check for the users timezone and it finds that its GMT - 5:00 so the database time will be subtracted with 5 (again exactly 5, not little more or little less) and displayed the user.
This will be great for system which is used in different timezones. So the understanding is the input is taken in the user's timezone stored in UTC(GMT-0) and displayed to user's timezone (even if the user viewing is in the different timezone the time will be accurate to their timezone)
Odoo display the datetime field AS TIMEZONE, in this case the timezone is GMT+1 but it will be GMT+0 in june because of ramadan, that's why

Resources