Adsutil

To convert a date into the format that an Active Directory uses as accountExpired date, use the following java code (compile it first) and place it in the $WSHOME/lib directory.

package custom;

import java.io.PrintStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class AdsUtil
{

    private static final long FILETIME_EPOCH_DIFF = 0xa9735dcc400L;
    private static final long HUNDRED_NANO_PER_MILLI_RATIO = 10000L;

    public static long dateToFiletime(Date date)
    {
        long l = date.getTime();
        long l1 = l + 0xa9735dcc400L;
        return l1 * 10000L;
    }

    public static Date filetimeToDate(long l)
    {
        long l1 = l / 10000L;
        long l2 = l1 - 0xa9735dcc400L;
        return new Date(l2);
    }

    private static boolean isNoExpireDS(String s)
    {
        boolean flag = false;
        if(s == null)
        {
            flag = true;
        } else
        {
            s = s.trim();
            Long long1 = new Long(1L);
            try
            {
                long1 = Long.decode(s);
            }
            catch(NumberFormatException numberformatexception) { }
            flag = flag || long1.longValue() == 0L;
            flag = flag || s.length() == 0;
        }
        return flag;
    }

    public static String DS2ADS(String s, String s1)
    {
        SimpleDateFormat simpledateformat = new SimpleDateFormat(s1);
        long l = 0L;
        if(isNoExpireDS(s))
            l = 0x7fffffffffffffffL;
        else
            try
            {
                Date date = simpledateformat.parse(s);
                l = dateToFiletime(date);
            }
            catch(ParseException parseexception) { }
        return new String(Long.toString(l));
    }

    public static String ADS2DS(String s, String s1)
    {
        SimpleDateFormat simpledateformat = new SimpleDateFormat(s1);
        long l = Long.parseLong(s);
        Date date = filetimeToDate(l);
        l = dateToFiletime(date);
        return new String(simpledateformat.format(date));
    }

    public AdsUtil()
    {
    }

    public static void main(String args[])
    {
        AdsUtil adsutil = new AdsUtil();
        String s = new String("2007-03-01");
        System.out.println(s + " : " + DS2ADS(s, "yyyy-MM-dd"));
        String s1 = new String("0000000000");
        System.out.println(s1 + " : " + DS2ADS(s1, "yyyy-MM-dd"));
    }
}

Then in a form use:

<Field name='global.accountExpires'>
 <Expansion>
  <invoke name='DS2ADS' class='custom.AdsUtil'>
   <ref>global.contractEndDate</ref>
   <s>yyyyMMdd</s>
  </invoke>
 </Expansion>
</Field>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License