22.08.2011, 23:11 | #1 |
Участник
|
daxline: Futures class in Dynamics AX
Источник: http://feedproxy.google.com/~r/blogs...namics-ax.html
============== In Dynamics AX, if you want to find a date in a period, chances are you would be using the DateTimeUtil class. Say, I want to find the date 3 months exactly from today. Assuming a month is of 30 days, I can call the DateTimeUtil::addDays() method. So my code to get that will be, view source print? Код: 1.print DateTimeUtil::date(DateTimeUtil::addDays (DateTimeUtil::utcNow(), 3 * 30)); Let us see this class in action. view source print? X++: 01.static void FuturesClass(Args _args) 02.{ 03. Futures future; 04. int i; 05. 06. // Setup a future class object with 365 days as a period 07. future = new Futures(systemDateGet(), 365, PeriodUnit::Day); 08. 09. future.next(); 10. 11. info(strFmt("Future date after 3 months from today is %1",future.transDate())); 12. 13. // Setup a future class object with 1 year as a period 14. future = new Futures(systemDateGet(), 1, PeriodUnit::Year); 15. 16. for (i=1; i<=3; i++) 17. { 18. future.next(); 19. } 20. 21. info(strFmt("Future date after 3 years from today is %1",future.transDate())); 22. 23. // Setup a future class object with 1 month as a period 24. future = new Futures(systemDateGet(), 1, PeriodUnit::Month); 25. 26. for (i=1; i<=3; i++) 27. { 28. future.next(); 29. } 30. 31. info(strFmt("Future date after 3 months from today is %1",future.transDate())); 32.} The Futures class is initialized by passing three values. The start date of the period, length of the period and the Period unit. The Period unit can be day, month or year. So when we create a new object specifying today's date as the start date, 15 as the period and day as the unit, it means each period in this instance will be 15 days long. So if I call the future.next() method, I will get a date exactly 15 days from now. So what are the advantages of this over the DateTimeUtil class? Well, the readibility of the code is obvious. Apart from this, you dont have to worry about missing days in a period and the extra calculation needed. For example, lets say today is 23rd August. August has 31 days, September 30 and October 31 days. So we need to add 92 days in total, which gives us 22nd November. But if I need to use the DateTimeUtil class for that, I have to do the days calculation myself whereas the Future's class handles this automatically. The Futures class is a nice little helper class which can be helpful when calculating periods of given length in days, months or years. I hope this post was helpful. Do send me your comments. Thats all for today, do check back soon. Источник: http://feedproxy.google.com/~r/blogs...namics-ax.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. Последний раз редактировалось Poleax; 26.08.2011 в 09:43. Причина: оформление |
|
|
Опции темы | Поиск в этой теме |
Опции просмотра | |
|