mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Second commit
This commit is contained in:
24
src/utils/localStorage.js
Normal file
24
src/utils/localStorage.js
Normal file
@ -0,0 +1,24 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||
|
||||
export async function getItem () {
|
||||
try {
|
||||
const value = await AsyncStorage.getItem('@social.xmflsct.com')
|
||||
if (!value) {
|
||||
await AsyncStorage.setItem(
|
||||
'@social.xmflsct.com',
|
||||
'qjzJ0IjvZ1apsn0_wBkGcdjKgX7Dao9KEPhGwggPwAo'
|
||||
)
|
||||
}
|
||||
return value
|
||||
} catch (e) {
|
||||
console.error('Get token error')
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllKeys () {
|
||||
try {
|
||||
return await AsyncStorage.getAllKeys()
|
||||
} catch (e) {
|
||||
console.error('Get all keys error')
|
||||
}
|
||||
}
|
25
src/utils/relativeTime.js
Normal file
25
src/utils/relativeTime.js
Normal file
@ -0,0 +1,25 @@
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
export default function relativeTime (date) {
|
||||
var units = {
|
||||
year: 24 * 60 * 60 * 1000 * 365,
|
||||
month: (24 * 60 * 60 * 1000 * 365) / 12,
|
||||
day: 24 * 60 * 60 * 1000,
|
||||
hour: 60 * 60 * 1000,
|
||||
minute: 60 * 1000,
|
||||
second: 1000
|
||||
}
|
||||
|
||||
var rtf = new Intl.RelativeTimeFormat('zh', { numeric: 'auto' })
|
||||
|
||||
var elapsed = new Date(date) - new Date()
|
||||
|
||||
// "Math.abs" accounts for both "past" & "future" scenarios
|
||||
for (var u in units)
|
||||
if (Math.abs(elapsed) > units[u] || u == 'second')
|
||||
return rtf.format(Math.round(elapsed / units[u]), u)
|
||||
}
|
||||
|
||||
relativeTime.propTypes = {
|
||||
date: PropTypes.string.isRequired
|
||||
}
|
Reference in New Issue
Block a user