mirror of https://github.com/tasks/tasks
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.4 KiB
Java
62 lines
2.4 KiB
Java
/**
|
|
* See the file "LICENSE" for the full license governing this code.
|
|
*/
|
|
package com.todoroo.astrid.api;
|
|
|
|
import java.util.Date;
|
|
|
|
import com.todoroo.andlib.utility.DateUtilities;
|
|
|
|
/**
|
|
* PermaSql allows for creating SQL statements that can be saved and used
|
|
* later without dates getting stale. It also allows these values to be
|
|
* used in
|
|
*
|
|
* @author Tim Su <tim@todoroo.com>
|
|
*
|
|
*/
|
|
public final class PermaSql {
|
|
|
|
// --- placeholder strings
|
|
|
|
/** value to be replaced with the current time as long */
|
|
public static final String VALUE_NOW = "NOW()"; //$NON-NLS-1$
|
|
|
|
/** value to be replaced by end of day as long */
|
|
public static final String VALUE_EOD = "EOD()"; //$NON-NLS-1$
|
|
|
|
/** value to be replaced by end of day yesterday as long */
|
|
public static final String VALUE_EOD_YESTERDAY = "EODY()"; //$NON-NLS-1$
|
|
|
|
/** value to be replaced by end of day tomorrow as long */
|
|
public static final String VALUE_EOD_TOMORROW = "EODT()"; //$NON-NLS-1$
|
|
|
|
/** value to be replaced by end of day day after tomorrow as long */
|
|
public static final String VALUE_EOD_DAY_AFTER = "EODTT()"; //$NON-NLS-1$
|
|
|
|
/** value to be replaced by end of day next week as long */
|
|
public static final String VALUE_EOD_NEXT_WEEK = "EODW()"; //$NON-NLS-1$
|
|
|
|
/** Replace placeholder strings with actual */
|
|
public static String replacePlaceholders(String value) {
|
|
if(value.contains(VALUE_NOW))
|
|
value = value.replace(VALUE_NOW, Long.toString(DateUtilities.now()));
|
|
if(value.contains(VALUE_EOD) || value.contains(VALUE_EOD_DAY_AFTER) ||
|
|
value.contains(VALUE_EOD_NEXT_WEEK) || value.contains(VALUE_EOD_TOMORROW) ||
|
|
value.contains(VALUE_EOD_YESTERDAY)) {
|
|
Date date = new Date();
|
|
date.setHours(23);
|
|
date.setMinutes(59);
|
|
date.setSeconds(59);
|
|
long time = date.getTime();
|
|
value = value.replace(VALUE_EOD_YESTERDAY, Long.toString(time - DateUtilities.ONE_DAY));
|
|
value = value.replace(VALUE_EOD, Long.toString(time));
|
|
value = value.replace(VALUE_EOD_TOMORROW, Long.toString(time + DateUtilities.ONE_DAY));
|
|
value = value.replace(VALUE_EOD_DAY_AFTER, Long.toString(time + 2 * DateUtilities.ONE_DAY));
|
|
value = value.replace(VALUE_EOD_NEXT_WEEK, Long.toString(time + 7 * DateUtilities.ONE_DAY));
|
|
}
|
|
return value;
|
|
}
|
|
|
|
}
|