Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Functional Programming
Diskuy-Frontend
Commits
cd739986
Commit
cd739986
authored
Feb 22, 2021
by
FadhilP
Browse files
fix timestamp time
parent
6c010370
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/helpers/time-util.js
View file @
cd739986
const
monthNames
=
[
'
January
'
,
'
February
'
,
'
March
'
,
'
April
'
,
'
May
'
,
'
June
'
,
'
July
'
,
'
August
'
,
'
September
'
,
'
October
'
,
'
November
'
,
'
December
'
,
];
function
tConvert
(
time
)
{
try
{
// Check correct time format and split into components
time
=
time
.
toString
()
.
match
(
/^
([
01
]\d
|2
[
0-3
])(
:
)([
0-5
]\d)(
:
[
0-5
]\d)?
$/
)
||
[
time
];
if
(
time
.
length
>
1
)
{
// If time format correct
time
=
time
.
slice
(
1
,
4
);
// Remove full string match value
time
[
5
]
=
+
time
[
0
]
<
12
?
'
AM
'
:
'
PM
'
;
// Set AM/PM
time
[
0
]
=
+
time
[
0
]
%
12
||
12
;
// Adjust hours
}
return
time
.
join
(
''
);
// return adjusted time or original string
}
catch
(
error
)
{}
}
import
moment
from
'
moment
'
;
function
translate
(
time
)
{
try
{
const
timeSplit
=
time
.
split
(
'
T
'
);
const
date
=
new
Date
(
timeSplit
[
0
]);
const
fullDate
=
`
${
date
.
getDate
()}
${
monthNames
[
date
.
getMonth
()]
}
${
date
.
getFullYear
()}
`
;
const
date
=
moment
(
time
).
utcOffset
(
new
Date
().
getTimezoneOffset
()
-
120
)
const
fullDate
=
moment
(
date
).
format
(
'
DD MMMM YYYY
'
)
const
timeStamp
=
moment
(
date
).
format
(
'
hh:mm A
'
)
return
`
${
fullDate
}
,
${
t
Convert
(
timeSplit
[
1
])
}
`
;
return
`
${
fullDate
}
,
${
t
imeStamp
}
`
;
}
catch
(
error
)
{}
}
export
{
tConvert
,
translate
};
export
{
translate
};
Write
Preview
Supports
Markdown
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