Last active
August 29, 2015 14:06
-
-
Save tyoshikawa1106/1c85289372fec0d97d83 to your computer and use it in GitHub Desktop.
月末月初取得処理
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
/** | |
* 月初日付取得 | |
*/ | |
public static Date getMonthOfStartDay(Date prmDate) { | |
return prmDate != null ? Date.newInstance(prmDate.year(), prmDate.month(), 1) : null; | |
} | |
/** | |
* 月末日付取得 | |
*/ | |
public static Date getMonthOfEndDay(Date prmDate) { | |
return prmDate != null ? Date.newInstance(prmDate.year(), prmDate.month() + 1 ,0) : null; | |
} |
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
// 実行ユーザ | |
private static User testAdminUser = new User(Id = UserInfo.getUserId()); | |
/** | |
* 月初日付取得 テスト | |
*/ | |
static testMethod void getMonthOfStartDayTest() { | |
System.runAs(testAdminUser) { | |
Test.startTest(); | |
Date result; | |
// 2014年01月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 01, 20)); | |
System.assertEquals(result, date.newInstance(2014, 01, 01)); | |
// 2014年02月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 02, 20)); | |
System.assertEquals(result, date.newInstance(2014, 02, 01)); | |
// 2014年03月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 03, 20)); | |
System.assertEquals(result, date.newInstance(2014, 03, 01)); | |
// 2014年04月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 04, 20)); | |
System.assertEquals(result, date.newInstance(2014, 04, 01)); | |
// 2014年05月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 05, 20)); | |
System.assertEquals(result, date.newInstance(2014, 05, 01)); | |
// 2014年06月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 06, 20)); | |
System.assertEquals(result, date.newInstance(2014, 06, 01)); | |
// 2014年07月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 07, 20)); | |
System.assertEquals(result, date.newInstance(2014, 07, 01)); | |
// 2014年08月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 08, 20)); | |
System.assertEquals(result, date.newInstance(2014, 08, 01)); | |
// 2014年09月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 09, 20)); | |
System.assertEquals(result, date.newInstance(2014, 09, 01)); | |
// 2014年10月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 10, 20)); | |
System.assertEquals(result, date.newInstance(2014, 10, 01)); | |
// 2014年11月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 11, 20)); | |
System.assertEquals(result, date.newInstance(2014, 11, 01)); | |
// 2014年12月 | |
result = CommonDate.getMonthOfStartDay(date.newInstance(2014, 12, 20)); | |
System.assertEquals(result, date.newInstance(2014, 12, 01)); | |
// 値なし | |
result = CommonDate.getMonthOfStartDay(null); | |
System.assertEquals(result, null); | |
Test.stopTest(); | |
} | |
} | |
/** | |
* 月末日付取得 テスト | |
*/ | |
static testMethod void getMonthOfEndDayTest() { | |
System.runAs(testAdminUser) { | |
Test.startTest(); | |
Date result; | |
// 2014年01月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 01, 10)); | |
System.assertEquals(result, date.newInstance(2014, 01, 31)); | |
// 2014年02月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 02, 10)); | |
System.assertEquals(result, date.newInstance(2014, 02, 28)); | |
// 2014年03月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 03, 10)); | |
System.assertEquals(result, date.newInstance(2014, 03, 31)); | |
// 2014年04月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 04, 10)); | |
System.assertEquals(result, date.newInstance(2014, 04, 30)); | |
// 2014年05月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 05, 10)); | |
System.assertEquals(result, date.newInstance(2014, 05, 31)); | |
// 2014年06月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 06, 10)); | |
System.assertEquals(result, date.newInstance(2014, 06, 30)); | |
// 2014年07月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 07, 10)); | |
System.assertEquals(result, date.newInstance(2014, 07, 31)); | |
// 2014年08月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 08, 10)); | |
System.assertEquals(result, date.newInstance(2014, 08, 31)); | |
// 2014年09月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 09, 10)); | |
System.assertEquals(result, date.newInstance(2014, 09, 30)); | |
// 2014年10月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 10, 10)); | |
System.assertEquals(result, date.newInstance(2014, 10, 31)); | |
// 2014年11月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 11, 10)); | |
System.assertEquals(result, date.newInstance(2014, 11, 30)); | |
// 2014年12月 | |
result = CommonDate.getMonthOfEndDay(date.newInstance(2014, 12, 10)); | |
System.assertEquals(result, date.newInstance(2014, 12, 31)); | |
// 値なし | |
result = CommonDate.getMonthOfEndDay(null); | |
System.assertEquals(result, null); | |
Test.stopTest(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment