Skip to content

Upgrade function since($stamp) to consider weeks, months, years #2008

Open

Description

@kuopassa

Is your feature request related to a problem?

Inside textpattern/lib/txplib_misc.php is the function since($stamp) which seems to present the since-format for certain timestamps. It doesn't seem to consider cases where several weeks, months or even years have passed.

What is the feature?

Include weeks, months and years in the function. Simple examples:

  • If timestamp is older than 7 days, show "1 week"
  • If timestamp is older than 31 days, show "1 month"
  • If timestamp is older than 366 days, show "1 year"

Activity

  1. Bloke commented on Aug 17, 2025

    @Bloke
    Member

    I absolutely swear I did this in some capacity in very recent memory. I distinctly remember rejigging some date/time function. Perhaps it was in a plugin or some shortcode in a side project, because the only reference I can find in the last 4 years in core is from 2021.

    Wish I could remember where I did this, because it was practically the same as this request. Regardless, yes, it's a good idea and not difficult.

    EDIT: Found it! It was a shortcode in a site:

    $now = new DateTime();
    $earlier = new DateTime(parse('<txp:posted format="%Y-%m-%d %H:%M:%S" />'));
    $diff = date_diff($earlier, $now);
    $yrs = ltrim($diff->format('%Y'), '0');
    $mths = ltrim($diff->format('%m'), '0');
    $days = ltrim($diff->format('%a'), '0');
    
    if ($yrs > 0) {
    echo $yrs.' year'.($yrs == 1 ? '' : 's').' ago';
    } elseif ($mths > 0) {
    echo $mths.' month'.($mths == 1 ? '' : 's').' ago';
    } elseif ($days > 0) {
    echo $days.' day'.($days == 1 ? '' : 's').' ago';
    } elseif ($days == 1) {
    echo 'yesterday';
    } elseif ($days == 0) {
    echo 'today';
    }
    
    
  2. self-assigned this
    on Aug 17, 2025
  3. added this to the v4.9.0 milestone on Aug 18, 2025
  4. bloatware commented on Aug 25, 2025

    @bloatware
    Member

    The only difficulty is text strings. Not sure it would be ready for 4.9.0.

  5. modified the milestones: v4.9.0, v4.9 on Aug 26, 2025
  6. added this to the v4.9 milestone on Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions