Skip to content

Instantly share code, notes, and snippets.

@khusamov
Last active April 29, 2020 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khusamov/2a9ce98bd1e5eff247502bdadaa4443a to your computer and use it in GitHub Desktop.
Save khusamov/2a9ce98bd1e5eff247502bdadaa4443a to your computer and use it in GitHub Desktop.
Как добавить дату и время сборки в приложение на CRA2?
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;
}
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