Skip to content

Commit

Permalink
move getDate to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
sunilshetye committed Oct 11, 2024
1 parent 63bff49 commit edb902a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
10 changes: 1 addition & 9 deletions blocks/eda-frontend/src/components/Dashboard/SchematicCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DeleteIcon from '@material-ui/icons/Delete'
import { useDispatch } from 'react-redux'
import { deleteSchematic } from '../../redux/actions/index'
import MuiAlert from '@material-ui/lab/Alert'
import { getDate } from '../../utils/GalleryUtils'

const useStyles = makeStyles((theme) => ({
media: {
Expand Down Expand Up @@ -93,15 +94,6 @@ function timeSince (jsonDate) {
return Math.floor(seconds) + ' seconds'
}

// Display schematic created date (e.g : Created On 29 Jun 2020)
function getDate (jsonDate) {
const json = jsonDate
const date = new Date(json)
const dateTimeFormat = new Intl.DateTimeFormat('en', { year: 'numeric', month: 'short', day: '2-digit' })
const [{ value: month }, , { value: day }, , { value: year }] = dateTimeFormat.formatToParts(date)
return `${day}-${month}-${year}`
}

// Card displaying overview of onCloud saved schematic.
export default function SchematicCard ({ sch }) {
const classes = useStyles()
Expand Down
10 changes: 1 addition & 9 deletions blocks/eda-frontend/src/components/SchematicEditor/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { deepPurple } from '@material-ui/core/colors'
import logo from '../../static/favicon.ico'
import { setTitle, logout, setSchTitle, setSchShared } from '../../redux/actions/index'
import store from '../../redux/store'
import { getDateTime as getDate } from '../../utils/GalleryUtils'

const useStyles = makeStyles((theme) => ({
toolbarTitle: {
Expand Down Expand Up @@ -170,15 +171,6 @@ function Header () {
}
}

// handle display format of last saved status
function getDate (jsonDate) {
const json = jsonDate
const date = new Date(json)
const dateTimeFormat = new Intl.DateTimeFormat('en', { month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })
const [{ value: month }, , { value: day }, , { value: hour }, , { value: minute }, , { value: second }] = dateTimeFormat.formatToParts(date)
return `${day} ${month} ${hour}:${minute}:${second}`
}

// handle Copy Share Url
const textAreaRef = useRef(null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { useSelector, useDispatch } from 'react-redux'
import { fetchSchematics, fetchSchematic, loadGallery } from '../../redux/actions/index'
import GallerySchSample from '../../utils/GallerySchSample'
import { blue } from '@material-ui/core/colors'
import { getDateTime as getDate } from '../../utils/GalleryUtils'

const Transition = forwardRef(function Transition (props, ref) {
return <Slide direction='up' ref={ref} {...props} />
Expand Down Expand Up @@ -387,14 +388,6 @@ export function OpenSchDialog (props) {
const auth = useSelector(state => state.authReducer)
const schematics = useSelector(state => state.dashboardReducer.schematics)

function getDate (jsonDate) {
const json = jsonDate
const date = new Date(json)
const dateTimeFormat = new Intl.DateTimeFormat('en', { month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })
const [{ value: month }, , { value: day }, , { value: hour }, , { value: minute }, , { value: second }] = dateTimeFormat.formatToParts(date)
return `${day} ${month} ${hour}:${minute}:${second}`
}

const dispatch = useDispatch()

const title = 'Open ' + process.env.REACT_APP_DIAGRAM_NAME
Expand Down
16 changes: 16 additions & 0 deletions blocks/eda-frontend/src/utils/GalleryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ export const transformXcos = async (xmlDoc) => {
xmlDoc = processor.transformToDocument(xmlDoc)
return xmlDoc
}

// handle display format of last saved status
export const getDateTime = (jsonDateTime) => {
const date = new Date(jsonDateTime)
const dateTimeFormat = new Intl.DateTimeFormat('en', { month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })
const [{ value: month }, , { value: day }, , { value: hour }, , { value: minute }, , { value: second }] = dateTimeFormat.formatToParts(date)
return `${day} ${month} ${hour}:${minute}:${second}`
}

// Display diagram created date (e.g : Created On 29 Jun 2020)
export const getDate = (jsonDate) => {
const date = new Date(jsonDate)
const dateTimeFormat = new Intl.DateTimeFormat('en', { year: 'numeric', month: 'short', day: '2-digit' })
const [{ value: month }, , { value: day }, , { value: year }] = dateTimeFormat.formatToParts(date)
return `${day}-${month}-${year}`
}

0 comments on commit edb902a

Please sign in to comment.