Question

Is there a method to create a live template which would give out the current timestamp by maybe pressing 't' + TAB in phpStorm:

I want to do this in the creation of the DocBlocks as I like to keep a track of the changes in the code, for Ex :

/**
 * This is the info for the doc.
 * User: sankalp
 * Date: 3/8/13   
 * Time: 10:58 AM <- I want the implementation here.
 * @author : sankalpsingha@gmail.com
 */

public function actionSomething(){

#some code here...
}

So is there a method to achieve this? Or would I have to use the see-the-watch-and-generate-your-own-timestamp approach?

Was it helpful?

Solution

From https://www.jetbrains.com/phpstorm/webhelp/file-templates.html:

File templates are written in the Velocity Template Language (VTL).

And apparently VTL predefines time as ${TIME}

/**
 * Created by ${PRODUCT_NAME}.
 * User: ${USER}
 * Date: ${DATE}
 * Time: ${TIME}
 * To change this template use File | Settings | File Templates.
 */

For Live Templates, see https://www.jetbrains.com/phpstorm/webhelp/live-templates.html

Go to the Live Templates. Create a new entry named t (or whatever you want) and put $TIME$ into the Template Text box. Set the context to PHP. Then click "Edit Variables" and select time() as the expression. Apply the changes. Next time you hit tab-t it will insert the current time.

However, when you want this to "keep a track of the changes in the code", then why not just use a Version Control System, like Git, Mercurial or SVN to keep track of the changes. Then you don't need the time in the DocBlock at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top