Page MenuHomePhabricator

Split MWTimestamp into a separate library
Closed, ResolvedPublic

Description

There's a good amount of code in MWTimestamp that is generally re-usable. Some methods are MW specific and probably shouldn't be in MWTimestamp to begin with...

  • getHumanTimestamp - https://gerrit.wikimedia.org/r/213355
  • offsetForUser (depends upon User and $wgLocalTZoffset)
  • getRelativeTimestamp - unused???
  • getLocalInstance (dependent upon $wgLocaltimezone)

Event Timeline

Legoktm created this task.May 31 2015, 8:53 AM
Legoktm raised the priority of this task from to Needs Triage.
Legoktm updated the task description. (Show Details)
Legoktm added a project: Librarization.
Legoktm added subscribers: Aklapper, Bawolff, Legoktm, Parent5446.

Change 213355 had a related patch set uploaded (by Legoktm):
Move MWTimestamp::getHumanTimestamp() to Language

https://gerrit.wikimedia.org/r/213355

To be honest, I'm not exactly sure how useful this really is. MWTimestamp is just a wrapper around PHP's native Timestamp class, and the only additional non-MW-specific functionality it provides is a parser for a bunch of obscure timestamp formats.

the only additional non-MW-specific functionality it provides is a parser for a bunch of obscure timestamp formats.

Yeah, that's the part we want to re-use.

Ah lol. Well in that case sounds good.

Change 213355 merged by jenkins-bot:
Move MWTimestamp::getHumanTimestamp() to Language

https://gerrit.wikimedia.org/r/213355

Jdforrester-WMF triaged this task as Low priority.Jun 9 2015, 3:42 PM
Jdforrester-WMF updated the task description. (Show Details)
Jdforrester-WMF set Security to None.

Here's what I'm imagining the class/library would look like:

<?php

namespace MediaWiki;

class Timestamp {

	const UNIX = "...";

	public function __construct( $input ) {
		$this->timestamp = $this->parseTimestamp( $input );
	}

	/**
	 * @param string $input
	 * @return \DateTime
	 * @throws SomeException
	 */
	private function parseTimestamp( $input ) {

	}

	/**
	 * @param int $format A TS_ constant
	 * @return string
	 */
	public function format( $format ) {

	}
}

Thoughts?

Are we considering the idea of allowing callees to register new timestamp types, and have them associate a parser with that type? Or is the format list just something we're going to keep fixed?

I was thinking of just keeping the list fixed....

Mhm, I agree. Just wanted to make sure. The interface you posted looks good. I'm assuming the intention is to make it a value object. Should we have transformation functions? Like ->add( Timestamp $other ), which returns a new Timestamp?

Krinkle moved this task from Untriaged to To Do on the Librarization board.Sep 4 2015, 4:06 AM
demon added a subscriber: demon.

Won't make 1.27 at this point.

Legoktm added a subscriber: aaron.Sep 21 2016, 3:12 AM

@aaron split out most of MWTimestamp into a generic ConvertibleTimestamp class in includes/libs!

We want https://gerrit.wikimedia.org/r/#/c/311881/ to land and then this can be moved into a separate repo/composer package

Change 312198 had a related patch set uploaded (by Legoktm):
Initial commit from MediaWiki core

https://gerrit.wikimedia.org/r/312198

Change 312198 merged by Legoktm:
Initial commit from MediaWiki core

https://gerrit.wikimedia.org/r/312198

Change 313682 had a related patch set uploaded (by Legoktm):
Add wikimedia/timestamp 1.0.0

https://gerrit.wikimedia.org/r/313682

Change 313683 had a related patch set uploaded (by Legoktm):
Use wikimedia/timestamp

https://gerrit.wikimedia.org/r/313683

Change 313682 merged by jenkins-bot:
Add wikimedia/timestamp 1.0.0

https://gerrit.wikimedia.org/r/313682

Change 313683 merged by jenkins-bot:
Use wikimedia/timestamp

https://gerrit.wikimedia.org/r/313683

Krinkle closed this task as Resolved.Mar 2 2017, 10:47 PM
Krinkle claimed this task.
Krinkle reassigned this task from Krinkle to Legoktm.