Skip to content

Instantly share code, notes, and snippets.

@alan-morey
Created July 24, 2012 21:46
Show Gist options
  • Save alan-morey/3172879 to your computer and use it in GitHub Desktop.
Save alan-morey/3172879 to your computer and use it in GitHub Desktop.
Apex ScheduleUtil
global class ScheduleUtil {
global static String cronExpression(DateTime dt) {
return dt.format('s m H d M ? yyyy');
}
static testMethod void testCronExpression() {
DateTime dt = DateTime.now();
String expected = dt.second() + ' ' + dt.minute() + ' ' + dt.hour() + ' ' + dt.day() + ' ' + dt.month() + ' ? ' + dt.year();
System.assertEquals(expected, cronExpression(dt));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment