Date functionality

General
manfeb14
2011-08-03
2013-05-28
  • manfeb14
    manfeb14
    2011-08-03

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <oddjob>
        <job>
            <folder>
                <jobs>
                    <variables id="var">
                        <sample>
                            <date date="${system.current}" format="dd-mm-yyyy"/>
                        </sample>
                    </variables>
                    <mkdir dir="C:\Mark\Mabs\Scheduler\${var.date}"/>
                </jobs>
            </folder>
        </job>
    </oddjob>

    hi .. i want to create a folder everyday with name as today date. i will doin this for taking back ups.. Butdate property is not working or sorry i dont know…

    i need to store the value of today's date in a variable.. so everyday when i run ( i will actually schedule it ) a folder of today's date should be created.

    please suggest..

     
  • Rob Gordon
    Rob Gordon
    2011-08-03

    Hi - Your problem is that you should reference the variable with ${var.sample}. sample is name of the property, date is the type. Also you should use format instead of date because you are trying to build a file name, not specify something that must be a java Date type.

    The dailyftp example in the examples directory does something very similar to what you want. I've simplified it to be close to what you want:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <scheduling:timer id="kcb-sched" name="KCB Schedule" timeZone="America/Chicago" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">
        <schedule>
            <schedules:time from="10:00" to="17:00" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules"/>
        </schedule>
        <job>
            <sequential id="kcb-trans" name="KCB Transfer Sequence">
                <jobs>
                    <variables id="kcb-vars">
                        <filedate>
                            <format date="${kcb-sched.current.fromDate}" format="yyyyMMdd" timeZone="America/Chicago"/>
                        </filedate>
                    </variables>
                    <mkdir dir="c:/Mark/Mabs/Scheduler/${kcb-vars.filedate}"/>
                </jobs>
            </sequential>
        </job>
    </scheduling:timer>

    Note that the date come from the timers current property.

    Rob.

     
  • manfeb14
    manfeb14
    2011-08-05

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <oddjob>
        <job>
            <scheduling:timer id="kcb-sched" name="KCB Schedule" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">
                <schedule>
                    <schedules:interval interval="00:00:25" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules"/>
                </schedule>
                <job>
                    <sequential id="kcb-trans" name="KCB Transfer Sequence">
                        <jobs>
                            <variables id="kcb-vars">
                                <filedate>
                                    <format date="${kcb-sched.current.fromDate}" format="dd-MM-yyyy"/>
                                </filedate>
                                <prevdate>
                                    <format date="${kcb-sched.current.fromDate}-1" format="dd-MM-yyyy"/>
                                </prevdate>
                                <nextdate>
                                    <format date="${kcb-sched.current.fromDate}+1" format="dd-MM-yyyy"/>
                                </nextdate>
                            </variables>
                            <echo text="hi current date is ${kcb-vars.filedate}"/>
                            <echo text="hi previous date  is ${kcb-vars.prevdate}"/>
                            <echo text="hi next  date  is ${kcb-vars.nextdate}"/>
                        </jobs>
                    </sequential>
                </job>
            </scheduling:timer>
        </job>
    </oddjob>

    Hi.. I want to get current date and also previous date and next date.. i will be scheduling this so that everyday a folder of today's date is created and files are tansferred from one location to there and previous date folder will be deleted and nextdate folder will be created..

    I am not able to get previous date and next date with current date from ${kcb-sched.current.fromDate}.

    I tried ${kcb-sched.current.fromDate}-1 , ${kcb-sched.current.fromDate}+1 and many other combinations,,,

    Pls suggest
    '

     
  • Rob Gordon
    Rob Gordon
    2011-08-08

    Oddjob doesn't support Expression Language type syntax for attribute values yet. To achieve what you want you will need a custom job that calculates the next and previous days. Something like this:

    package scratch;

    import java.util.Calendar;
    import java.util.Date;

    public class Dates implements Runnable {

    private Date current;
    private Date previous;
    private Date next;

    @Override
    public void run() {
    Calendar cal = Calendar.getInstance();

    cal.setTime(current);
    cal.add(Calendar.DAY_OF_MONTH, -1);
    previous = cal.getTime();

    cal.setTime(current);
    cal.add(Calendar.DAY_OF_MONTH, +1);
    next = cal.getTime();

    }

    public Date getCurrent() {
    return current;
    }

    public void setCurrent(Date current) {
    this.current = current;
    }

    public Date getPrevious() {
    return previous;
    }

    public Date getNext() {
    return next;
    }

    @Override
    public String toString() {
    return "Dates";
    }
    }

    The configuration becomes:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <oddjob>
        <job>
            <scheduling:timer id="kcb-sched" name="KCB Schedule" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">
                <schedule>
                    <schedules:interval interval="00:00:25" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules"/>
                </schedule>
                <job>
                    <sequential id="kcb-trans" name="KCB Transfer Sequence">
                        <jobs>
                            <bean class="scratch.Dates" id="my-dates">
                                <current>
                                    <value value="${kcb-sched.current.fromDate}"/>
                                </current>
                            </bean>
                            <variables id="kcb-vars">
                                <filedate>
                                    <format date="${my-dates.current}" format="dd-MM-yyyy"/>
                                </filedate>
                                <prevdate>
                                    <format date="${my-dates.previous}" format="dd-MM-yyyy"/>
                                </prevdate>
                                <nextdate>
                                    <format date="${my-dates.next}" format="dd-MM-yyyy"/>
                                </nextdate>
                            </variables>
                            <echo text="hi current date is ${kcb-vars.filedate}"/>
                            <echo text="hi previous date is ${kcb-vars.prevdate}"/>
                            <echo text="hi next date is ${kcb-vars.nextdate}"/>
                        </jobs>
                    </sequential>
                </job>
            </scheduling:timer>
        </job>
    </oddjob>

    For more information on writing your own jobs see the developer guide.

    Rob.