예제 #1
0
    private long getCutoffTime(String val, BackupTarget target)
        throws ServiceException, IOException
    {
        if(val.indexOf('/') != -1)
            try
            {
                return Utils.parseDate(val);
            }
            catch(ParseException e)
            {
                throw ServiceException.INVALID_REQUEST((new StringBuilder()).append("invalid date: ").append(val).toString(), e);
            }
        String d = val.toLowerCase().trim();
        if(d.endsWith("d") || d.endsWith("m") || d.endsWith("y"))
        {
            int len = d.length();
            char unit = d.charAt(len - 1);
            int num = Integer.parseInt(d.substring(0, len - 1));
            if(num < 0)
                throw ServiceException.INVALID_REQUEST("invalid cutoff period: negative value means cutoff date in the future", null);
            Calendar today = Calendar.getInstance();
            switch(unit)
            {
            case 100: // 'd'
                today.add(5, -num);
                break;

            case 109: // 'm'
                today.add(2, -num);
                break;

            case 121: // 'y'
                today.add(1, -num);
                break;
            }
            return today.getTimeInMillis();
        } else
        {
            return BackupManager.getLabelDate(val);
        }
    }