Angular UI bootstrap timepicker uses new Date() as a model, how do elegantly wrap it to display UTC time to the user? - angular-ui

http://angular-ui.github.io/bootstrap/#/timepicker
Angular UI bootstrap timepicker uses "new Date()" as a model, how do elegantly wrap it to display UTC time to the user? (new Date() uses local timezone)
I'm using momentjs to manage my datetimes but when i bind it to this directive it converts it to my local timezone.
I was trying to avoid adding the timezone offset hours on the way in, and subtracting them on the way out? I was hoping for something more elegant or Angular-y.
Or is there a better alternative directive?

You could try creating the date on your model using Date.UTC:
// controller
$scope.utcDate = new Date(Date.UTC(year, month, day, hour, minute, second));
<!-- view -->
<timepicker ng-model="utcDate"></timepicker>
Untested, so it probably won't work.
Alternatively, super long shot, you could try binding to the output of moment.utc() and hoping for the best :-).

Related

Is there anyway to use v-date-picker in Vue.js as date-time and not only as date?

What I am trying to do is use only v-date-picker without any other time-pickers. I was wondering if there is any way to change the type of v-date-picker in VueJS to be able to pick also hours, minutes and seconds (besides date). Thanks in advance!
You could try with https://github.com/darrenfang/vuetify-datetime-picker
<v-datetime-picker label="Select Datetime" v-model="datetime"> </v-datetime-picker>

Vaadin Datefield doesn't recognize weeks in SimpleDateTime formats

My core problem is that I want to show the year's week number and the year itself in a Vaadin date-field. For example the user picks the 6th February 2018. The date-field should format its value like "06 2018".
As I understood the documentation of Vaadin 7.7.13, this should easily possible with:
public class CalendarWeekField extends DateField {
public CalendarWeekField() {
super();
this.setLocale(UI.getCurrent().getLocale());
this.setDateFormat("ww yyyy");
this.setShowISOWeekNumbers(true);
}
Please recognize the line this.setDateFormat("ww yyyy"); since it contains the actual "magic".
The date and time are normally displayed according to the default
format for the current locale (see Locale). You can specify a custom
format with setDateFormat(). It takes a format string that follows the
format of the SimpleDateFormat in Java.
However, following the above example, the output of the DateField is only " 2018".
What do I need to consider to get the year's week numbers displayed?
Consulted documentations:
Java SimpleDateFormat
Vaadin Date and Time Input with DateField - Date and Time Format
Vaadin 7.7.13 API Documentation DateField - setDateFormat(...)
I would call this a bug, your code is fine. You can even "fiddle around" with their live sampler (hit properties -> date format), the field excepts most date patterns but ww (and apparently some timezone-properties). File a bug report maybe?
Maybe you can walk around it by applying a change listener and using .setText() yourself? You would not need to extend the DateField in that case (actually there is no need to extend the field in the first place, simply create and set your properties).

Date format upon retrieval

I am trying to retrieve dates from database in a recordset and print dates in mm/dd/yy mm:ss format in the view. Is it possible to intercept data in the model while retrieval and do formatting there instead of looping over recordset in the controller and reformatting dates in the controller before sending it to the view.
Is there a way in handlebars to format dates in the view without writing a helper function ?
Please help.
Thank you.
To format all my data, I created a service "utils" and pass it formatting libraries like moment.js. Your question asked if the handlebars could do this, and I don't know, but this method gives you the freedom to utilize any library. Reference http://sailsjs.org/#/documentation/concepts/Services
this "utilService" has a few libraries that help with formatting.
// utilService.js - in api/services
var changeCase = require("change-case"),
moment = require("moment"),
numeral = require("numeral");
module.exports = {
numeral : numeral,
moment : moment,
changeCase : changeCase
}
then I can use it in my view pages as utilService.moment(DATE).format('YYYY-MM-DD')

XPages: create current Datetime in ssjs and save to a Datetime Notes form field

The only way i have found to store date in a Datetime field in a notes form is this:
theDoc2.replaceItemValue("lastAccess",session.createDateTime("Today"));
But this only creates a Date, not DateTime. Also, i dont want to create a static time like "Today 12" but i want the current datetime dynamicly.
Using this i get an error (Exception occurred calling method NotesDocument.replaceItemValue(string, Date) null):
theDoc2.replaceItemValue("lastAccess",#Now());
and using this, the form field changes from Date/Time to Text data type and i want to keep Date/Time type:
theDoc2.replaceItemValue("lastAccess",#Now().toLocaleString);
Any ideas?
Just gave it a try:
as you wrote, .replaceItemValue("fieldName", #Now()) throws an error.
However, I got it to work with
.replaceItemValue("fieldName", session.createDateTime(#Now()))
In that case the value is stored in the Notes field as Time/Date with all necessary components as in
17.01.2014 12:45:51 CET
From what I can see, difference between the two is that #Now() returns a Date data type, whereas session.createDateTime() returns a NotesDateTime object
On the other hand, for me it's also working with your original method:
session.createDateTime("Today")
Don't know what's causing the prob on your side; do you have an editable represantion of the field on you xpage? If so, does it have some kind of converter enabled which could do some filtering during submit?
i will answer my own question as i found a way. Please comment if you think it is not correct or best practice...
theDoc2.replaceItemValue("lastAccess",session.createDateTime("Today"+#Now().toLocaleTimeString()));
A little late, but I had the same problem, but this method resolved it:
DateTime datumtijd = session.createDateTime("Today");
datumtijd.setNow(); //!!!!!!
System.out.println((datumtijd).toString());
Hope it helps :)

Custom date format (callback with php logic)

I want to create a dynamic php date format. Example: show the time of the node if it was published today and only the day/month when older then today. I want this format to be available throughout Drupal like the other predefined date formats in Drupal (not just on theme level).
I found the (D7 only) hook for hook_date_format_types but even that one doesn't seem to allow for a callback where I could define this PHP logic.
Does anyone know which hook would make this possible? Or a module which does this?
In Drupal6, format_date() has the dates and times hardcoded. Also, format_date() does not allow callbacks, but it does allow a custom string. That is where you can apply a trick: instead of hardcoding the string in there, you call a function that returns a string.
function mydate_format($timestamp) {
$now = time();
if (($now - $timestamp) < (60*60*24)) {
return "H:i";
}
else {
return "d:m:Y";
}
}
print format_date($timestamp, 'custom', mydate_format($timestamp));
The second option is to re-define a date-timestamp, but that is both hackish and limited. Date-formats are defined with variable_get(), but don't pass the timestamp along; so your example of switching formats based on the value of timestamp is not possible this way.
In settings.php:
$conf['date_format_long'] = $conf['debug'] ? 'r' : 'l, F j, Y - H:i';
This will switch from one value to another, based on whether your settings.php has a flag "debug" set to TRUE or not. As mentioned: the use for this is limited, since you cannot get any context.
The third alternative is to use Date API which offers onlinle configurable time-formats. But that is both clumsy and insecure (inputting executable PHP in your database). It also depends on a very large module-set. And has the same downside as the first solution: you cannot use format_date, but must use a modified function call, instead of format_date(). See all the options at The Drupal.org date themeing handbook.
GOTCHA In all cases Drupal will not call this function for cached content. If you want to have the dates really dynamic you either need to avoid caching alltogether, or implement the date-formatting in clientside javascript.
TL;DR: You cannot have dynamic date-formats without changing some of the code on theme-level. Using a callback-function to generate the "custom" dateformat is the simplest, working solution.
You can use Date API module to add your custom date formatting. Date API module is inside the Date module. After enabling the Date API module you can go the path "admin/settings/date-time/formats/add" to add your custom format.
"admin/settings/date-time/formats/configure" is the path to configure date formats.
Have a look at these. Happy coding.
Thanks
RT
You can go to node.tpl.php(possibly in sites/all/themes/theme_name/node.tpl.php). Here yo can find $created variable, to reformat date you can use your custom function and change the $created as you want.After this all nodes will use your formatted dates.
Regatds,
Chintan.
Use the features module. Create a feature.
In the resulting feature module, on the [feature].module file, create a hook_nodeapi function and format the field with a conditional statement that takes into account the current date() for how the date will be displayed and feed it into the $node->content var.
And that is the way rockstars would do it (-;

Resources