build.xml to set date and time as file name
Asked Answered
G

1

6

I want to set file name with date and time attached to it so I want to create file named as behat-20140913-195915.html however the example below sets the name as behat-yyyymmdd-hhiiss.html. Anyone know the solution to problem?

I followed this example

Note: These two don't work too: ${DSTAMP} ${TSTAMP}

<?xml version="1.0" encoding="UTF-8"?>

<project name="Sport" default="build-default" basedir=".">

    <tstamp>
        <format property="TODAY_MY" pattern="yyyymmdd-hhiiss"  locale="en,UK" />
    </tstamp>

    <target name="build" description="Runs everything in order ..." depends="behat-bdd" />

    <target name="behat">
        <echo msg="Running Behat tests ..." />
        <exec logoutput="true" checkreturn="true"
              command="bin/behat -f progress --format html --out ${dir-report}/behat-${TODAY_MY}.html" dir="./" />
    </target>

</project>
Groves answered 13/9, 2014 at 17:32 Comment(0)
F
15

The tstamp task is documented in the ANT manual. It describes how the pattern format comes from the SimpleDateFormat object:

I suggest trying the following:

Example

Buildfile: build.xml

build:
     [echo] date: 20140913-203419

build.xml

<project name="demo" default="build">

  <tstamp>
      <format property="TODAY_MY" pattern="yyyyMMdd-HHmmss"  locale="en,UK" />
  </tstamp>

  <target name="build">
    <echo message="date: ${TODAY_MY}"/>
  </target>

</project>

Software versions

$ ant -v
Apache Ant(TM) version 1.9.4 compiled on April 29 2014

$ java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
Foxe answered 13/9, 2014 at 19:34 Comment(5)
I got this instead as terminal output for bin/phing build-ts: [echo] date: yyyyMMdd-HHmmss. Note: I'm on Ubuntu 14.04Groves
@MadMax What versions of Java and ANT are you using?Occupy
I'm using Symfony2 with behat and phing. We're using same thing at work sith MAC PC and it works fine however it doesn't at home in LAMP environment. Ant is not installed cos phing is supposed to do all.Groves
@MadMax I don't use Phing, but it's my understanding it's written in PHP... Are you certain the tstamp task works the same way?Occupy
You've just givent me hint so looks like we're using it in a different way! <target name="behat-report"><tstamp/><exec logoutput="true" checkreturn="true" passthru="true" command="bin/behat --format html --out reports/behat-${DSTAMP}${TSTAMP}.html" /></target>. Thanks for the hint and +1Groves

© 2022 - 2024 — McMap. All rights reserved.