You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Satheesh <sa...@ltp.soft.net> on 2007/04/27 11:51:12 UTC

How to set the next week start date

Hi Guys, If i want to set the current date its possible in ANT , even if i want a date which is some 'n' days after the current date, that also is possible..

I need a way to set the value of the next weeks start date and last week start date using ANT.

How can i achieve this///

RE: How to set the next week start date

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
to quick ;-) 

corrected =

<project name="bla" default="main" basedir=".">

    <target name="depends">

    <script language="ruby">
    <![CDATA[
        
        t = Time.now
        puts t.strftime("actual date == %m.%d.%Y")
        x=t.strftime("%w").to_i-1
       
        thisweek = (t - x * 86400).strftime("%m.%d.%Y")
        $project.setProperty "thisweek",  thisweek
        
        lastweek = (t - x * 86400 - 7 * 86400).strftime("%m.%d.%Y")
        $project.setProperty "lastweek",  lastweek

        nextweek =  (t - x * 86400 + 7 * 86400).strftime("%m.%d.%Y")
        $project.setProperty "nextweek",  nextweek
    		
    ]]>
    </script>		

    </target>

    <target name="main" depends="depends">

    <echo>
        starting Date last week == ${lastweek}
        starting Date this week == ${thisweek}
        starting Date next week == ${nextweek}
    </echo>

    </target>
</project>

Buildfile: C:\WKS\eclipse_3_2_2\test\jruby_time.xml
depends:
   [script] actual date == 04.27.2007
main:
     [echo] starting Date last week == 04.16.2007
     [echo] starting Date this week == 04.23.2007
     [echo] starting Date next week == 04.30.2007
BUILD SUCCESSFUL
Total time: 2 seconds 


Regards, Gilbert


-----Original Message-----
From: Rebhan, Gilbert 
Sent: Friday, April 27, 2007 1:39 PM
To: 'Ant Users List'
Subject: RE: How to set the next week start date

 
Hi,

quick hack  =


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: How to set the next week start date

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 
Hi,

quick hack  =

<project name="bla" default="main" basedir=".">

    <target name="depends">

    <script language="ruby">
    <![CDATA[
        
        t = Time.now
        puts t.strftime("actual date == %m.%d.%Y")
        x=t.strftime("%w").to_i-1

        lastweek = (t - x * 86400).strftime("%m.%d.%Y")
        $project.setProperty "lastweek",  lastweek

        nextweek =  (t - x * 86400 + 7 * 86400).strftime("%m.%d.%Y")
        $project.setProperty "nextweek",  nextweek
    		
    ]]>
    </script>		

    </target>

    <target name="main" depends="depends">

    <echo>
        starting Date last week == ${lastweek}
        starting Date next week == ${nextweek}
    </echo>

    </target>
</project>


Buildfile: C:\WKS\eclipse_3_2_2\test\jruby_time.xml
depends:
   [script] actual date == 04.27.2007
main:
     [echo] starting Date last week == 04.23.2007
     [echo] starting Date next week == 04.30.2007
BUILD SUCCESSFUL
Total time: 2 seconds


the example uses Monday as starting point, if you want
Sunday instead you have to change the line

x=t.strftime("%w").to_i-1

to

x=t.strftime("%w").to_i

for having the date properties in other formats, you
have to alter the strftime("%m.%d.%Y") string, see

http://www.ruby.ch/ProgrammingRuby/htmlC/ref_c_time.html#strftime



Regards, Gilbert


-----Original Message-----
From: Satheesh [mailto:satish@ltp.soft.net] 
Sent: Friday, April 27, 2007 11:51 AM
To: Ant Users List
Subject: How to set the next week start date

Hi Guys, If i want to set the current date its possible in ANT , even if
i want a date which is some 'n' days after the current date, that also
is possible..

I need a way to set the value of the next weeks start date and last week
start date using ANT.

How can i achieve this///

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org