Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
boco-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106_2022_02
boco-frontend
Commits
f1e1f07f
Commit
f1e1f07f
authored
2 years ago
by
Haakon Tideman Kanter
Browse files
Options
Downloads
Patches
Plain Diff
Added time and date for messages
parent
35f1fde6
No related branches found
No related tags found
1 merge request
!119
New chat2
Pipeline
#181272
passed
2 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/ChatComponents/ChatMessage.vue
+45
-2
45 additions, 2 deletions
src/components/ChatComponents/ChatMessage.vue
with
45 additions
and
2 deletions
src/components/ChatComponents/ChatMessage.vue
+
45
−
2
View file @
f1e1f07f
...
@@ -58,17 +58,60 @@ export default {
...
@@ -58,17 +58,60 @@ export default {
:
"
justify-end
"
;
:
"
justify-end
"
;
},
},
calculateTime
()
{
calculateTime
()
{
var
time
=
this
?.
message
.
timestamp
;
var
date
=
new
Date
(
time
);
//Todo add timing for mm and hh and week of message
var
mmOfMessage
=
String
(
date
.
getMinutes
());
var
hhOfMessage
=
String
(
date
.
getHours
());
var
ddOfMessage
=
String
(
date
.
getDate
()).
padStart
(
2
,
'
0
'
);
var
dayOfMessage
=
date
.
toLocaleString
(
'
default
'
,
{
weekday
:
'
short
'
});
var
monthOfMessage
=
String
(
date
.
getMonth
()
+
1
).
padStart
(
2
,
'
0
'
);
//January is 0!
const
shortMonthOfMessage
=
date
.
toLocaleString
(
'
default
'
,
{
month
:
'
short
'
});
var
yyyyOfMessage
=
date
.
getFullYear
();
var
today
=
new
Date
();
var
dd
=
String
(
today
.
getDate
()).
padStart
(
2
,
'
0
'
);
var
mm
=
String
(
today
.
getMonth
()
+
1
).
padStart
(
2
,
'
0
'
);
//January is 0!
var
yyyy
=
today
.
getFullYear
();
if
(
ddOfMessage
==
dd
){
return
""
+
hhOfMessage
+
"
:
"
+
mmOfMessage
+
""
;
}
else
if
(
this
.
isDateInThisWeek
(
date
)){
return
""
+
dayOfMessage
+
"
"
+
hhOfMessage
+
"
:
"
+
mmOfMessage
;
}
else
if
(
monthOfMessage
==
mm
){
return
""
+
ddOfMessage
+
"
"
+
hhOfMessage
+
"
:
"
+
mmOfMessage
;
}
else
if
(
yyyyOfMessage
==
yyyy
){
return
""
+
shortMonthOfMessage
+
"
"
+
ddOfMessage
;
}
return
shortMonthOfMessage
+
"
"
+
ddOfMessage
+
"
"
+
yyyyOfMessage
+
""
;
/*
/*
Take timestamp and display date when message was sent
Take timestamp and display date when message was sent
If message was sent this day show time (HH:MM) (13:00)
If message was sent this day show time (HH:MM) (13:00)
If message was sent this week show day of the week and time (DDD HH:MM) (Mon 13:00)
If message was sent this week show day of the week and time (DDD HH:MM) (Mon 13:00)
If message was sent this month show day of the month, date and time (DD HH:MM) (13 13:00)
If message was sent this month show day of the month, date and time (DD HH:MM) (13 13:00)
If message was sent this year show month and day of the month (MM DD) (Jan 13)
If message was sent this year show month and day of the month (MM
M
DD) (Jan 13)
If message was sent more than a year ago show year with date (MMM DD YYYY) (Jan 13 2020)
If message was sent more than a year ago show year with date (MMM DD YYYY) (Jan 13 2020)
*/
*/
return
"
13:00
"
},
},
isDateInThisWeek
(
date
)
{
const
todayObj
=
new
Date
();
const
todayDate
=
todayObj
.
getDate
();
const
todayDay
=
todayObj
.
getDay
();
// get first date of week
const
firstDayOfWeek
=
new
Date
(
todayObj
.
setDate
(
todayDate
-
todayDay
));
// get last date of week
const
lastDayOfWeek
=
new
Date
(
firstDayOfWeek
);
lastDayOfWeek
.
setDate
(
lastDayOfWeek
.
getDate
()
+
6
);
// if date is equal or within the first and last dates of the week
return
date
>=
firstDayOfWeek
&&
date
<=
lastDayOfWeek
;
},
},
},
};
};
</
script
>
</
script
>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment