AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 22.08.2011, 23:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
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));
There is another application class in Dynamics AX, which does exactly this. This is the Futures class.

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 output is

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. Причина: оформление
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
dynamics-ax: Interview with Microsoft's Lachlan Cash on his new role, AX 2012 and more Blog bot DAX Blogs 6 22.04.2011 14:55
axinthefield: Dynamics AX Event IDs Blog bot DAX Blogs 0 01.03.2011 22:11
daxdilip: Whats New in Dynamics AX 2012 (A brief extract from the recently held Tech Conf.) Blog bot DAX Blogs 7 31.01.2011 12:35
dynamics-ax: Official Details about Dynamics AX '6' released, including comments from Microsofts Kees Hertogh Blog bot DAX Blogs 0 11.01.2011 05:22
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 09:21.