Get TimeZone offset?
mrQQ
Member Posts: 239
Hello,
how can I get TZ offset in hours using dotnet libraries? No matter what I try, it always comes up as empty for me
how can I get TZ offset in hours using dotnet libraries? No matter what I try, it always comes up as empty for me
0
Comments
-
so this works fine on C#:
DateTimeOffset dto = new DateTimeOffset(DateTime.Now); MessageBox.Show(dto.Offset.Hours.ToString());
but I cannot do this on NAV:dto := dto.DateTimeOffset(dt.Now); ts := dto.Offset;
because on the line ts := dto.Offset I get--------------------------- Microsoft Dynamics NAV Development Environment --------------------------- Assignment is not allowed for this variable. --------------------------- OK ---------------------------
and if I try to do Message(FORMAT(dto.Offset.Hours)) I get--------------------------- Microsoft Dynamics NAV Development Environment --------------------------- The variable is not a record. 'Variable.Field' is invalid. --------------------------- OK ---------------------------
0 -
ok, appearently TimeSpan is mapped to Duration, so if I replace ts type to Duration, assignement works fine, however Duration still comes up empty, even though in VS it works fine..0
-
what's even worse, if I set DTO to RunOnClient=Yes, it crashes the RTC client
0 -
It's not possible using pure C/AL. NAV runtime intercepts any assignment of .NET variables, and immediately maps the type that directly maps to an NAV type. There is no way to prevent it, as long as you are using DotNet variables. You could write your own assembly that wraps the methods you need, and then you could call it.
To illustrate the depth of the problem, I can provide this code:Assembly := Assembly.Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86'); o := Assembly.CreateInstance('System.TimeSpan'); arr := arr.CreateInstance(GETDOTNETTYPE(Type),1); arr.SetValue(GETDOTNETTYPE(''),0); m := Assembly.GetType.GetMethod('CreateInstance',arr); arr := arr.CreateInstance(GETDOTNETTYPE(''),1); arr.SetValue('System.TimeSpan',0); o := m.Invoke(Assembly,arr); MESSAGE('%1',o.GetType);
Obviously, I never handled System.TimeSpan directly, I used the most complicated reflection I could think of to create an instance of System.TimeSpan, but NAV runtime has still intercepted the output of the m.Invoke, which has indeed returned System.TimeSpan, and has converted it into Microsoft.Dynamics.Nav.Runtime.NavDuration immediately as it was returned from the method call.
So - unfortunately, nothing at the C/AL level that you can do. Sorry.(Co-)author of "Implementing Microsoft Dynamics NAV 2009"
http://vjeko.com/0 -
clear..
however, do you have any clue as to why the returned duration is empty, instead of containing TZ offset?0 -
hm.. could it be that dt.Now gets converted to NAV DateTime, before being passet to the constructor, and in process loses "Kind" property/information..?0
-
Can't really tell what's wrong there. It may be a bug in the implementation.(Co-)author of "Implementing Microsoft Dynamics NAV 2009"
http://vjeko.com/0 -
do you know where should I report this?0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 328 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions