Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getTimeString = timestamp => {
var DAY_IN_SECONDS = 3600 * 24,
MAX_LENGTH = 15,
parsedTime = Date.parse( timestamp ),
momentTime,
timeString;
if ( isNaN( parsedTime ) ) {
return '';
}
const localeSlug = getLocaleSlug();
momentTime = moment( timestamp ).locale( localeSlug );
if ( Date.now() - parsedTime > 1000 * DAY_IN_SECONDS * 5 ) {
// 30 Apr 2015
timeString = momentTime.format( 'll' );
if ( timeString.length > MAX_LENGTH ) {
// 2015/4/30 if 'll' is too long, e.g. "30 de abr. de 2015"
timeString = momentTime.format( 'l' );
}
} else {
// simplified units, no "ago", e.g. 7 min, 4 hours, 2 days
timeString = momentTime.fromNow( true );
}
return timeString;
export function localizeUrl( fullUrl, locale ) {
const localeSlug = locale || ( typeof getLocaleSlug === 'function' ? getLocaleSlug() : 'en' );
const urlParts = url.parse( String( fullUrl ) );
if ( ! urlParts ) {
return fullUrl;
}
// Let's unify the URL.
urlParts.protocol = 'https';
if ( 'en.wordpress.com' === urlParts.hostname ) {
urlParts.host = 'wordpress.com';
}
if ( ! endsWith( urlParts.pathname, '.php' ) ) {
urlParts.pathname = ( urlParts.pathname + '/' ).replace( /\/+$/, '/' );
}
if ( ! localeSlug || 'en' === localeSlug ) {
export function parseUnitPeriods( unit, period ) {
let splitYearWeek;
const localeSlug = getLocaleSlug();
switch ( unit ) {
case 'week':
splitYearWeek = period.split( '-W' );
return moment()
.locale( localeSlug )
.isoWeekYear( splitYearWeek[ 0 ] )
.isoWeek( splitYearWeek[ 1 ] )
.endOf( 'isoWeek' );
case 'month':
return moment( period, 'YYYY-MM' )
.locale( localeSlug )
.endOf( 'month' );
case 'year':
return moment( period, 'YYYY' )
.locale( localeSlug )
function getWporgLocaleCode() {
const currentLocaleCode = i18n.getLocaleSlug();
let wpOrgLocaleCode = find( languages, { langSlug: currentLocaleCode } ).wpLocale;
if ( wpOrgLocaleCode === '' ) {
wpOrgLocaleCode = currentLocaleCode;
}
return wpOrgLocaleCode;
}
i18n.registerTranslateHook( ( translation, options ) => {
const locale = i18n.getLocaleSlug();
if ( 'en' === locale ) {
return translation;
}
if ( i18n.hasTranslation( options.original ) ) {
if ( options.components ) {
translation = interpolateComponents( {
mixedString: options.original,
components: options.components,
} );
} else {
translation = options.original;
}
return translation;
}
export default function humanDate(
dateOrMoment,
dateFormat = 'll',
locale = i18n.getLocaleSlug()
) {
const now = moment().locale( locale );
dateOrMoment = moment( dateOrMoment ).locale( locale );
let millisAgo = now.diff( dateOrMoment );
if ( millisAgo < 0 ) {
millisAgo = 0;
}
if ( millisAgo < MILLIS_IN_MINUTE ) {
return i18n.translate( 'just now' );
}
if ( millisAgo < MILLIS_IN_MINUTE * 60 ) {
const minutes = Math.ceil( millisAgo / MILLIS_IN_MINUTE );
return i18n.translate( '%(minutes)dm ago', {
return this.props.backUrl;
}
const previousStep = this.getPreviousStep();
const stepSectionName = get(
this.props.signupProgress,
[ previousStep.stepName, 'stepSectionName' ],
''
);
return getStepUrl(
previousStep.lastKnownFlow || this.props.flowName,
previousStep.stepName,
stepSectionName,
getLocaleSlug()
);
}
getCurrentLanguage() {
return find( config( 'languages' ), { langSlug: i18n.getLocaleSlug() } );
}
export const shouldTranslateWord = word => i18n.getLocaleSlug() !== config( 'i18n_default_locale_slug' ) || ! isRomanAlphabetWord( word );