-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
297 additions
and
0 deletions.
There are no files selected for viewing
292 changes: 292 additions & 0 deletions
292
force-app/main/default/classes/RelativeDateConverter.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,292 @@ | ||
public with sharing class RelativeDateConverter { | ||
|
||
// ! https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm | ||
|
||
public class Wrapper { | ||
public Date DateValueStart {get; set;} | ||
public Date DateValueEnd {get; set;} | ||
public Datetime DatetimeValueStart {get; set;} | ||
public Datetime DatetimeValueEnd {get; set;} | ||
} | ||
|
||
|
||
public static Wrapper convert(String relativeDate){ | ||
|
||
if(String.isBlank(relativeDate)){ | ||
return null; | ||
} | ||
|
||
Wrapper result = new Wrapper(); | ||
|
||
List<String> inputParts = relativeDate.split(':'); | ||
|
||
eNumRelativeDate eNumInput = eNumRelativeDate.valueOf(inputParts[0]); | ||
|
||
Integer N; | ||
|
||
if(inputParts.size() > 1){ | ||
N = Integer.valueOf(inputParts[1]); | ||
} | ||
|
||
System.debug(eNumInput); | ||
System.debug(N); | ||
|
||
Date today = System.today(); | ||
|
||
/* | ||
result.DateValueStart = ; | ||
result.DateValueEnd = ; | ||
result.DatetimeValueStart = ; | ||
result.DatetimeValueEnd = ; | ||
*/ | ||
|
||
switch on eNumInput{ | ||
when YESTERDAY { | ||
// Starts at 12:00:00 AM on the day before the current day and continues for 24 hours. | ||
} | ||
when TODAY { | ||
// Starts at 12:00:00 AM on the current day and continues for 24 hours. | ||
} | ||
when TOMORROW { | ||
// Starts at 12:00:00 AM. on the day after the current day and continues for 24 hours. | ||
} | ||
when LAST_WEEK { | ||
// Starts at 12:00:00 AM on the first day of the week before the current week and continues for seven days. | ||
} | ||
when THIS_WEEK { | ||
// Starts at 12:00:00 AM on the first day of the current week and continues for seven days. | ||
} | ||
when NEXT_WEEK { | ||
// Starts at 12:00:00 AM on the first day of the week after the current week and continues for seven days. | ||
} | ||
when LAST_MONTH { | ||
// Starts at 12:00:00 AM on the first day of the month before the current month and continues for all the days of that month. | ||
} | ||
when THIS_MONTH { | ||
// Starts at 12:00:00 AM on the first day of the current month and continues for all the days of that month. | ||
} | ||
when NEXT_MONTH { | ||
// Starts at 12:00:00 AM on the first day of the month after the current month and continues for all the days of that month. | ||
} | ||
when LAST_90_DAYS { | ||
// Starts at 12:00:00 AM 90 days before the current day and continues up to the current second. | ||
// (The range includes today. Using this date value includes records from 91 days ago up to the current day.) | ||
} | ||
when NEXT_90_DAYS { | ||
// Starts at 12:00:00 AM on the day that the report is run and continues for 90 days. | ||
// (The range includes today.) | ||
} | ||
when LAST_N_DAYS { | ||
// Starts at 12:00:00 AM n days before the current day and continues up to the current second. | ||
// (The range includes today. Using this date value includes records from n + 1 days ago up to the current day.) | ||
// In standard filters, n can be 7, 30, 60, 90, or 120. | ||
} | ||
when NEXT_N_DAYS { | ||
// For standard date filters, starts at 12:00:00 AM on the day that the report is run and continues for n days. | ||
// (The range includes today.) | ||
// In standard filters, n can be 7, 30, 60, 90, or 120. | ||
// | ||
// For custom field filters, starts at 12:00:00 AM on the next day and continues for the next n days. | ||
// (The range does NOT include today.) | ||
} | ||
when N_DAYS_AGO { | ||
// Starts at 12:00:00 AM on the day n days before the current day and continues for 24 hours. | ||
// (The range does NOT include today.) | ||
} | ||
when NEXT_N_WEEKS { | ||
// Starts at 12:00:00 AM on the first day of the week after the current week and continues for n times seven days. | ||
} | ||
when LAST_N_WEEKS { | ||
// Starts at 12:00:00 AM on the first day of the week that started n weeks before the current week, and continues up to 11:59 PM on the last day of the week before the current week. | ||
} | ||
when N_WEEKS_AGO { | ||
// Starts at 12:00:00 AM on the first day of the week that started n weeks before the start of the current week and continues for seven days. | ||
} | ||
when NEXT_N_MONTHS { | ||
// Starts at 12:00:00 AM on the first day of the month after the current month and continues until the end of the nth month. | ||
} | ||
when LAST_N_MONTHS { | ||
// Starts at 12:00:00 AM on the first day of the month that started n months before the current month and continues up to 11:59 PM on the last day of the month before the current month. | ||
} | ||
when N_MONTHS_AGO { | ||
// Starts at 12:00:00 AM on the first day of the month that started n months before the start of the current month and continues for all the days of that month. | ||
} | ||
when THIS_QUARTER { | ||
// Starts at 12:00:00 AM on the first day of the current calendar quarter and continues to the end of the quarter. | ||
} | ||
when LAST_QUARTER { | ||
// Starts at 12:00:00 AM on the first day of the calendar quarter before the current calendar quarter and continues to the end of that quarter. | ||
} | ||
when NEXT_QUARTER { | ||
// Starts at 12:00:00 AM on the first day of the calendar quarter after the current calendar quarter and continues to the end of that quarter. | ||
} | ||
when NEXT_N_QUARTERS { | ||
// Starts at 12:00:00 AM on the first day of the calendar quarter after the current quarter and continues to the end of the calendar quarter n quarters in the future. | ||
// (The range does NOT include the current quarter.) | ||
} | ||
when LAST_N_QUARTERS { | ||
// Starts at 12:00:00 AM on the first day of the calendar quarter n quarters ago and continues to the end of the calendar quarter before the current quarter. | ||
// (The range does NOT include the current quarter.) | ||
} | ||
when N_QUARTERS_AGO { | ||
// Starts at 12:00:00 AM on the first day of the calendar quarter n quarters before the current calendar quarter and continues to the end of that quarter. | ||
} | ||
when THIS_YEAR { | ||
// Starts at 12:00:00 AM on January 1 of the current year and continues through the end of December 31 of the current year. | ||
} | ||
when LAST_YEAR { | ||
// Starts at 12:00:00 AM on January 1 of the year before the current year and continues through the end of December 31 of that year. | ||
} | ||
when NEXT_YEAR { | ||
// Starts at 12:00:00 AM on January 1 of the year after the current year and continues through the end of December 31 of that year. | ||
} | ||
when NEXT_N_YEARS { | ||
// Starts at 12:00:00 AM on January 1 of the year after the current year and continues through the end of December 31 of the nth year. | ||
} | ||
when LAST_N_YEARS { | ||
// Starts at 12:00:00 am on January 1, n+1 years ago. The range ends on December 31 of the year before the current year. | ||
} | ||
when N_YEARS_AGO { | ||
// Starts at 12:00:00 AM on January 1 of the calendar year n years before the current calendar year and continues through the end of December 31 of that year. | ||
} | ||
when THIS_FISCAL_QUARTER { | ||
// Starts at 12:00:00 AM on the first day of the current fiscal quarter and continues through the end of the last day of the current fiscal quarter. | ||
// The fiscal quarter is defined on the Fiscal Year page in Setup. | ||
} | ||
when LAST_FISCAL_QUARTER { | ||
// Starts at 12:00:00 AM on the first day of the fiscal quarter before the current fiscal quarter and continues through the last day of that fiscal quarter. | ||
// The fiscal quarter is defined on the Fiscal Year page in Setup. | ||
} | ||
when NEXT_FISCAL_QUARTER { | ||
// Starts at 12:00:00 AM on the first day of the fiscal quarter after the current fiscal quarter and continues through the last day of that fiscal quarter. | ||
// (The range does NOT include the current quarter.) | ||
// The fiscal quarter is defined on the Fiscal Year page in Setup. | ||
} | ||
when NEXT_N_FISCAL_QUARTERS { | ||
// Starts at 12:00:00 AM on the first day of the fiscal quarter after the current fiscal quarter and continues through the end of the last day of the nth fiscal quarter. | ||
// (The range does NOT include the current fiscal quarter.) | ||
// The fiscal quarter is defined on the Fiscal Year page in Setup. | ||
} | ||
when LAST_N_FISCAL_QUARTERS { | ||
// Starts at 12:00:00 AM on the first day of the fiscal quarter n fiscal quarters ago and continues through the end of the last day of the previous fiscal quarter. | ||
// (The range does NOT include the current fiscal quarter.) | ||
// The fiscal quarter is defined on the Fiscal Year page in Setup. | ||
} | ||
when N_FISCAL_QUARTERS_AGO { | ||
// Starts at 12:00:00 AM on the first day of the fiscal quarter n fiscal quarters before the current fiscal quarter and continues through the end of the last day of that fiscal quarter. | ||
} | ||
when THIS_FISCAL_YEAR { | ||
// Starts at 12:00:00 AM on the first day of the current fiscal year and continues through the end of the last day of the fiscal year. | ||
// The fiscal quarter is defined on the Fiscal Year page in Setup. | ||
} | ||
when LAST_FISCAL_YEAR { | ||
// Starts at 12:00:00 AM on the first day of the fiscal year before the current fiscal year and continues through the end of the last day of that fiscal year. | ||
// The fiscal quarter is defined on the Fiscal Year page in Setup. | ||
} | ||
when NEXT_FISCAL_YEAR { | ||
// Starts at 12:00:00 AM on the first day of the fiscal year after the current fiscal year and continues through the end of the last day of that fiscal year. | ||
// The fiscal quarter is defined on the Fiscal Year page in Setup. | ||
} | ||
when NEXT_N_FISCAL_YEARS { | ||
// Starts at 12:00:00 AM on the first day of the fiscal year after the current fiscal year and continues through the end of the last day of the nth fiscal year. | ||
// (The range does NOT include the current fiscal year.) | ||
// The fiscal quarter is defined on the Fiscal Year page in Setup. | ||
} | ||
when LAST_N_FISCAL_YEARS { | ||
// Starts at 12:00:00 AM on the first day of the fiscal year n fiscal years ago and continues through the end of the last day of the fiscal year before the current fiscal year. | ||
// (The range does NOT include the current fiscal year.) | ||
// The fiscal quarter is defined on the Fiscal Year page in Setup. | ||
} | ||
when N_FISCAL_YEARS_AGO { | ||
// Starts at 12:00:00 AM on the first day of the fiscal year n fiscal years ago and continues through the end of the last day of that fiscal year. | ||
} | ||
when else { | ||
// | ||
} | ||
} | ||
|
||
return result; | ||
|
||
} | ||
|
||
/************************************************************************************** | ||
* @Description Passing in the number of days for calculation | ||
* @Param numDays - number of days to use in calculation, negative is days before, zero is today, positive is days in the future | ||
* @Return Wrapper - calculated start and end date/datetime | ||
**************************************************************************************/ | ||
private Wrapper days(Integer numDays){ | ||
return new Wrapper(); | ||
} | ||
|
||
private Wrapper weeks(Integer numWeeks){ | ||
return new Wrapper(); | ||
} | ||
|
||
private Wrapper months(Integer numMonths){ | ||
return new Wrapper(); | ||
} | ||
|
||
private Wrapper quarters(Integer numQuarters){ | ||
return new Wrapper(); | ||
} | ||
|
||
private Wrapper years(Integer numYears){ | ||
return new Wrapper(); | ||
} | ||
|
||
private Wrapper fiscalQuarters(Integer numQuarters){ | ||
return new Wrapper(); | ||
} | ||
|
||
private Wrapper fiscalYears(Integer numYears){ | ||
return new Wrapper(); | ||
} | ||
|
||
public enum eNumRelativeDate { | ||
YESTERDAY, | ||
TODAY, | ||
TOMORROW, | ||
LAST_WEEK, | ||
THIS_WEEK, | ||
NEXT_WEEK, | ||
LAST_MONTH, | ||
THIS_MONTH, | ||
NEXT_MONTH, | ||
LAST_90_DAYS, | ||
NEXT_90_DAYS, | ||
LAST_N_DAYS, | ||
NEXT_N_DAYS, | ||
N_DAYS_AGO, | ||
NEXT_N_WEEKS, | ||
LAST_N_WEEKS, | ||
N_WEEKS_AGO, | ||
NEXT_N_MONTHS, | ||
LAST_N_MONTHS, | ||
N_MONTHS_AGO, | ||
THIS_QUARTER, | ||
LAST_QUARTER, | ||
NEXT_QUARTER, | ||
NEXT_N_QUARTERS, | ||
LAST_N_QUARTERS, | ||
N_QUARTERS_AGO, | ||
THIS_YEAR, | ||
LAST_YEAR, | ||
NEXT_YEAR, | ||
NEXT_N_YEARS, | ||
LAST_N_YEARS, | ||
N_YEARS_AGO, | ||
THIS_FISCAL_QUARTER, | ||
LAST_FISCAL_QUARTER, | ||
NEXT_FISCAL_QUARTER, | ||
NEXT_N_FISCAL_QUARTERS, | ||
LAST_N_FISCAL_QUARTERS, | ||
N_FISCAL_QUARTERS_AGO, | ||
THIS_FISCAL_YEAR, | ||
LAST_FISCAL_YEAR, | ||
NEXT_FISCAL_YEAR, | ||
NEXT_N_FISCAL_YEARS, | ||
LAST_N_FISCAL_YEARS, | ||
N_FISCAL_YEARS_AGO | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/RelativeDateConverter.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>56.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |