Telligent 10 - Velocity Template - get current datetime - velocity

Using Telligent 10 platform and their native Velocity Template Language, how can we simply get the current datetime?
Per the many examples I've seen here on SO these first two require the $date var previously defined and those examples all define the date statically not by getting the current system datetime so the following do not work:
#set ($today = $date.getCurrentDate())
<span>$today</span>
#set ($today = $date.getDate())
<span>$today</span>
Per this Telligent Community thread I read that Telligent uses .NET DateTime (of which I'm very familiar) but ... these don't work either in Widget Studio:
#set ($today = DateTime.Now)
<span>$today</span>
#set ($today = new DateTime)
<span>$today.Now</span>

Found it. I overlooked the properties (literally the first section) outlined for the $core_v2_utility.
We can get the current date by using the following:
$core_v2_utility.CurrentDate

Related

RStudio Error: Unused argument ( by = ...) when fitting gam model, and smoothing seperately for a factor

I am still a beginnner in R. For a project I am trying to fit a gam model on a simple dataset with a timeset and year. I am doing it in R and I keep getting an error message that claims an argument is unused, even though I specify it in the code.
It concerns a dataset which includes a categorical variable of "Year", with only two levels. 2020 and 2022. I want to investigate if there is a peak in the hourly rate of visitors ("H1") in a nature reserve. For each observation period the average time was taken, which is the predictor variable used here ("T"). I want to use a Gam model for this, and have the smoothing applied differently for the two years.
The following is the line of code that I tried to use
`gam1 <- gam(H1~Year+s(T,by=Year),data = d)`
When I try to run this code, I get the following error message
`Error in s(T, by = Year) : unused argument (by = Year)`
I also tried simply getting rid of the "by" argument
`gam1 <- gam(H1~Year+s(T,Year),data = d)`
This allows me to run the code, but when trying to summon the output using summary(gam1), I get
Error in [<-(tmp, snames, 2, value = round(nldf, 1)) : subscript out of bounds
Since I feel like both errors are probably related to the same thing that I'm doing wrong, I decided to combine the question.
Did you load the {mgcv} package or the {gam} package? The latter doesn't have factor by smooths and as such the first error message is what I would expect if you did library("gam") and then tried to fit the model you showed.
To fit the model you showed, you should restart R and try in a clean session:
library("mgcv")
# load you data
# fit model
gam1 <- gam(H1 ~ Year + s(T, by = Year), data = d)
It could well be that you have both {gam} and {mgcv} loaded, in which case whichever you loaded last will be earlier on the function search path. As both packages have functions gam() and s(), R might just be finding the wrong versions (masking), so you might also try
gam1 <- mgcv::gam(H1 ~ Year + mgcv::s(T, by = Year), data = d)
But you would be better off only loading {mgcv} if you wan factor by smooths.
#Gavin Simpson
I did have both loaded, and I tried just using mgcv as you suggested. However, then I get the following error.
Error in names(dat) <- object$term :
'names' attribute [1] must be the same length as the vector [0]
I am assuming this is simply because it's not actually trying to use the "gam" function, but rather it attempts to name something gam1. So I would assume I actually need the package of 'gam' before I could do this.
The second line of code also doesn't work. I get the following error
Error in model.frame.default(formula = H1 ~ Year + mgcv::s(T, by = Year), :
invalid type (list) for variable 'mgcv::s(T, by = Year)'
This happens no matter the order I download the two packages in. And if I don't download 'gam', I get the error as described above.

Karate: How to use a Javascript function from a DIFFERENT feature file

I have created a feature file that will contain lots of javascript functions.
From within a DIFFERENT feature file I want to use ONE of those functions (and pass in a value).
How do I do this please?
My feature file is called SystemSolentraCustomKarateMethods.feature
Here is the current content (it currently contains just one function):
Feature: System Solentra Status Test
Background:
* def checkreturneddatetimeiscorrect =
#The following code compares the passed in datetime with the current systemdatetime and
#makes sure they are within 2 seconds of each other
"""
function(datetime) {
var datenow = new Date();
karate.log("***The Date Now = " + datenow.toISOString() + " ***");
var timenow = datenow.getTime();
karate.log("***The Time Now in Milliseconds = " + timenow+ " ***");
karate.log("***The Passedin Date = " + datetime + " ***");
var passedintime = new Date();
passedintime = Date.parse(datetime);
karate.log("***The Passed in Time = " + passedintime+ " ***");
var difference = timenow - passedintime;
karate.log("***The Time Difference = " + difference + " milliseconds ***");
return (difference < 2000)
}
"""
Thanks Peter I have figured out how to do this now.
(1) The feature file that contains the functions MUST have the Feature, Background and Scenario tags - even if your file does NOT contain any scenarios. (*see my example file below)
(2) In the feature file that you are calling FROM add the following code to the Background section:
* call read('yourfilename.feature')
(3) You can now use the functions within the called feature file
Here is the structure of the feature file I am calling:
Feature: Custom Karate Methods
This feature file contains Custom Karate Methods that can be called and used from other Feature Files
Background:
* def *nameofyourfunction* =
#Comment describing the fuction
"""
function() {
*code*
}
"""
****Scenario: This line is required please do not delete - or the functions cannot be called****
I think you've already seen the answer here, and this question is an exact duplicate: https://stackoverflow.com/a/47002604/143475 (edit: ok, maybe not)
Anyway, I'll repeat what I posted there:
there is no problem when you define multiple functions in one feature and call it from multiple other features
you will anyway need a unique name for each function
when you use call for that feature, all the functions will be available, yes, but if you don't use them, that's okay. if you are worrying about performance and memory, IMHO that is premature optimization
if that does not sound good enough, one way to achieve what you want is to define a Java class Foo with a bunch of static methods. then you can do Foo.myMethodOne(), Foo.myMethodTwo() to your hearts content. I would strongly recommend this approach in your case, because you seem to be expecting an explosion of utility methods, and in my experience, that is better managed in Java, just because you can maintain that code better, IDE support, unit-tests, debugging and all
Hope that makes sense !

Send UTC timestamps with moment.js to ASP.NET Core controller

I have a database with measured values from devices that I want to display in a web frontend. First I send the list of devices to the frontend together with the IANA timezone specifier for each device.
I would like all timestamps to be exchanged as UTC. The user selects a time range in the frontend in device-local time. I use moment.js to convert these timestamps to UTC with the known timezone of the device like this:
var startTimestamp = new Date(2017, 7, 1); //some local timestamp (zero-based month!)
var m = moment.tz(startTimestamp, "Europe/Berlin");
var utc = moment.utc(m).format();
utc is now "2017-07-31T22:00:00Z" which seems to be correct given the 2 hours offset for Berlin in DST.
I send this utc timestamp to my ASP.NET Core backend. The controller looks like this:
[HttpGet]
public IEnumerable<TimestampedValue> GetValues(int id, DateTime startTimestamp)
{
...
}
The problem is that startTimestamp is 2017-08-01 00:00:00 when the controller is called and its Kind property is set to Local. I would have expected it to be the same UTC timestamp.
Any idea what I'm doing wrong? I think moment.js is doing its job correctly so this must be a problem on the server side. If I recall correctly, the deserialization is done by JSON.net but I don't understand why it does not respect the Z at the end of the time string.
After #dbc pointed me to the different behavior between GET and POST requests I come to this conclusion:
Since my request uses the GET method and query strings are not JSON, there is no JSON.net involved in the problem, it is the default .NET Core DateTimeConverter that does the conversion. Moment.js correctly converts the timestamp to a UTC string, I checked that using the browser developer tools.
The code for DateTimeConverter can be found here:
https://github.com/dotnet/corefx/blob/312736914d4e98c2948778bacac029aa831dd6b5/src/System.ComponentModel.TypeConverter/src/System/ComponentModel/DateTimeConverter.cs
As can be seen there, the converter uses DateTime.Parse. It can be tested in a simple test project that DateTime.Parse does not respect the Z-suffix. This is also discussed here DateTimeConverter converting from UTC string.
I think there would be at least four solutions
1) write a custom model binder. These SOs each show a part of it Custom DateTime model binder in ASP.NET Core 1 (RTM)
https://dotnetcoretutorials.com/2016/12/28/custom-model-binders-asp-net-core/
2) write a custom type converter that overrides the default DateTime converter and checks whether there is a trailing Z. If so, use DateTime.Parse with the DateTimeStyles.AdjustToUniversal. Else fall back to the default implementation. I like this solution but I currently don't know how to replace the default DateTimeConverter.
3) replace all relevant DateTime parameters in the controllers with DateTimeOffset. DateTimeOffset seems to correctly convert the UTC string.
4) use a POST instead of a GET request with JSON in the request body. JSON.net seems to correctly convert the UTC string.
My preferred solution is currently a mixture of 3 and 4, depending on the context.

Getting view options in Microsoft Project using VBA

If I want to change the current date format to 20, for example, I can use the command
OptionsViewEx DateFormat:=20
but how can I get the current date format (or any other view option for that matter)?
DefaultDateFormat should be the function to use.
oldvalue = Application.DefaultDateFormat
Application.DefaultDateFormat = 20 ' or = pjDate_mm_dd_yyyy
This gets or sets the default date format. (technet)
This gives the complete list of format types.
If you use Date function get a date in current format, but if you need change use format(Date,"yyyy-mmmm-dd") for example.

How do I retrieve the locale-specific date format string in Flex / ActionScript 3?

How do I retrieve the locale-specific date format string in Flex / ActionScript 3? I am unable to find a method to return the actual format string (that which specifies the date format) based on the current locale. I am asking this question because I was hoping to find a way to convert a String to a Date based on the current SHORT date format for the locale. Java allows one to call:
DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale)
to retrieve an instance of DateFormat that formats according to the SHORT format based on the locale.
Does similar functionality exist in Adobe Flex (ActionScript 3) 3? If not, is there a reliable third party library that exists for this?
I'm just found this package that do the job. Here describe the class DateTimeFormatter:
var formatter:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.LONG, DateTimeStyle.SHORT);
var result:String = formatter.format(date);
Just cool.
Extending Gojan's answer:
private function cc(event:FlexEvent):void {
var formatter:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.SHORT, DateTimeStyle.NONE);
//now if publishDate is a mx:DateField, the formatString of spark and mx components are slightly different.
//So, we replace all d with D and y with Y
publishDate.formatString=replaceAll(formatter.getDateTimePattern(), ["d", "y"], ["D", "Y"]);
}
private function replaceAll(text:String, searchArray:Array, replArray:Array):String {
for (var i:int=0; i<searchArray.length; i++) {
var s:String=searchArray[i];
var d:String=replArray[i];
text=text.split(s).join(d);
}
return text;
}
Yeah I have to say Java is better with dates - you set the locale and automatically your dates are outputted correctly! I can't seem to find such a facility in Flex.
In order to output your dates correctly for each locale I think you have to do what is written in this article: http://livedocs.adobe.com/flex/3/html/help.html?content=l10n_1.html. Maybe you should do this, and in the same class just make these strings which you've pulled from the locale file available to the rest of your app, then you'll be able to operate on them.
Otherwise perhaps this guy's library will help you? I'm not sure.
http://flexoop.com/2008/12/flex-date-utils-date-and-time-format-part-ii/