Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for inconsistent dates cross platform #1002

Merged
merged 14 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/views/identity/administration/UserSigninLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,42 @@ const rowStyle = (row, rowIndex) => {
return style
}

function timeConversion(s) {
let AMPM = s.slice(-2)
let timeArr = s.slice(0, -2).split(':')
if (AMPM === 'AM' && timeArr[0] === '12') {
// catching edge-case of 12AM
timeArr[0] = '00'
} else if (AMPM === 'PM') {
// everything with PM can just be mod'd and added with 12 - the max will be 23
timeArr[0] = (timeArr[0] % 12) + 12
}
return timeArr.join(':')
}

//This is so dirty but I need to do this to solve the inconsistent dates
//between macos and windows
function FixDate(date) {
if (date === null) {
return null
}
try {
var noLinesDate = date.toString().replace(/\n/g, '').trim()
if (noLinesDate.toString().includes('AM') || noLinesDate.toString().includes('PM')) {
var onlyTime = noLinesDate.slice(-11)
if (onlyTime[0] === ' ') {
onlyTime = '0' + onlyTime.replace(' ', '').replace(' ', '')
}
onlyTime = timeConversion(onlyTime.replace(' ', '').replace(' ', ''))
noLinesDate = noLinesDate.slice(0, -11) + ' ' + onlyTime
}
return noLinesDate + 'Z'
} catch {
console.error('error returning date')
return 'error'
}
}

function ConvertErrorCode(row) {
try {
return row['LoginStatus']
Expand Down Expand Up @@ -100,7 +136,7 @@ export default function UserSigninLogs({ userId, tenantDomain, className = null
const columns = [
{
name: 'Date (Local)',
selector: (row) => row['Date'].toString().trim() + 'Z',
selector: (row) => FixDate(row['Date']),
exportSelector: 'Date',
minWidth: '145px',
cell: cellDateFormatter(),
Expand Down
8 changes: 7 additions & 1 deletion src/views/tenant/conditional/ConditionalAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import { useSelector } from 'react-redux'
import { CippPageList } from 'src/components/layout'
import { CippActionsOffcanvas } from 'src/components/utilities'
import { cellDateFormatter, CellTip } from 'src/components/tables'
function DateNotNull(date) {
if (date === null || date === undefined || date === '' || date === 'undefined') {
return ' '
}
return date.toString().trim() + 'Z'
}
const Offcanvas = (row, rowIndex, formatExtraData) => {
const tenant = useSelector((state) => state.app.currentTenant)
const [ocVisible, setOCVisible] = useState(false)
Expand Down Expand Up @@ -98,7 +104,7 @@ const columns = [
},
{
name: 'Last Modified (Local)',
selector: (row) => row['modifiedDateTime'].toString().trim() + 'Z',
selector: (row) => DateNotNull(row['modifiedDateTime']),
sortable: true,
cell: cellDateFormatter(),
exportSelector: 'modifiedDateTime',
Expand Down