Last active
April 29, 2020 17:14
-
-
Save khusamov/2a9ce98bd1e5eff247502bdadaa4443a to your computer and use it in GitHub Desktop.
Как добавить дату и время сборки в приложение на CRA2?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import preval from 'preval.macro'; | |
const buildDate = new Date(Number(preval`module.exports = new Date().getTime();`)); | |
/** | |
* Дата сборки. | |
* @link https://stackoverflow.com/questions/53028778/how-to-show-build-datetime-on-my-react-web-app-using-create-react-app | |
* @link https://gist.github.com/khusamov/2a9ce98bd1e5eff247502bdadaa4443a | |
*/ | |
export default function getBuildDate(): Date { | |
return buildDate; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import preval from 'preval.macro'; | |
import moment from 'moment'; | |
const buildTimestamp = Number(preval`module.exports = new Date().getTime();`); | |
const lastUpdateMoment = moment.unix(buildTimestamp / 1000); | |
/** | |
* Дата сборки в виде строки. | |
* @link https://stackoverflow.com/questions/53028778/how-to-show-build-datetime-on-my-react-web-app-using-create-react-app | |
* @link https://gist.github.com/khusamov/2a9ce98bd1e5eff247502bdadaa4443a | |
*/ | |
export default function getBuildDateString(): string { | |
return lastUpdateMoment.format('DD.MM.YYYY HH:mm:ss'); | |
} | |
/** | |
* Дата сборки. | |
*/ | |
export function getBuildDate(): Date { | |
return lastUpdateMoment.toDate(); | |
} | |
/** | |
* Год сборки. | |
*/ | |
export function getBuildYear(): number { | |
return lastUpdateMoment.year(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment