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).
Related
How to change native easy admin 3 in symfony date/time picker time format? It now renders month, day, year. How do you set to 'Y-m-d H:i'?
If you look in the source code for the DateTimeField you will find a setFormat method that accepts a valid ICU Datetime Pattern (see http://userguide.icu-project.org/formatparse/datetime).
The format of a native date picker is determined by the browser's native code and locale settings, you cannot change it with out some complicated scripting (see here). This may possibly update the format of a choice or text type (not tested).
Try something like this:
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
public function configureFields(string $pageName): iterable
{
return [
// native date picker format cannot be changed
// Uses native HTML5 widgets when rendering this field in forms.
DateTimeField::new('beginsAt')->setFormat('Y-MM-dd HH:mm')->renderAsNativeWidget(),
// Uses <select> lists when rendering this field in forms.
DateTimeField::new('beginsAt')->setFormat('Y-MM-dd HH:mm')->renderAsChoice(),
// Uses <input type="text"> elements when rendering this field in forms.
DateTimeField::new('beginsAt')->setFormat('Y-MM-dd HH:mm')->renderAsText(),
];
}
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 :)
I've got a Issue with SharePoint 2013 Files in Libraries. If I push an File via WebDAV into an Folder the file will still hold it's created/modified date (and that's good!).
Other Case is: I use the "New Document" Upload Form - the File will be newly created and loses its correct created/modified date.
I'm looking for a way to get these correct Values of the SPFile Item.
DateTime modified = Li.File.TimeLastModified;
That's my current attempt to get the DateTime but it only retrieves the "sharepoint" value and not the "filesystem" value of the LastModifiedDate.
I tried to let my Webpart open the File on the server.. but URI-Formats arent supported :-(
Has anybody already run into this problem?
Thanks for your help in advance!
EDIT:
This is what I get in explorer view of the document library. For example the file lync.PNG has a last modified date of 26.12.2013.
this is what I get from my webpart using the code snippet (sorry for the german description; "geƤndert am" means lastmodifieddate)
You can get the modified date that SharePoint uses by getting the Item of the SPFile then reading the date property. Something like this:
DateTime date = DateTime.Parse(file.Item["Modified"].ToString());
Once its in SharePoint any changes should come from the modified property of the item. You would have to use an event receiver to capture the original file date and then overwrite the SharePoint created date, or add the value to another field in the item.
Hope this helps.
First of all: I am running a Plonce Plone 4.3 (4305) instance with Dexterity Content Types 2.0.7
My approach is to write a Python Script (added via ZMI) which creates my dexterity content type using the methods invokeFactory(...) or typestool.constructContent(..) described here: http://plone.org/documentation/kb/add-content-programmatically (I've written two scripts which do the same task but use different methods - for learning purposes)
Everything is working fine, except when i try to add a DateTime Object to the constructor of both methods above to create my Content Type. The Date field strangly only updates the day and year values. Because of the restrictions in importing libraries inside python i am stuck (with my current knowledge) with this code:
d = DateTime('12/12/2013')
My script returns the date object after completion which looks like this:
2013/12/12 00:00:00 GMT+1
I've written another small script which outputs the Date value after construction and it gives me the same result (which seems to be correct). The resulting Content Type has its day and year field updated correctly but the month value stays on January and raises the following TypeError upon viewing:
TypeError: int() argument must be a string or a number, not 'instancemethod'
I can fix this by editing the month value manually which is not exactly what i want. I guess it its a minor problem with my DateTime object but i am running out of ideas at this point (overall documentation seems to be a bit scattered). I've tried various date formats inside the DateTime constructor but without luck.
I am also not sure how to modifiy my objects custom field values. Plone seems only to provide setTitle() and setDescription() methods. Maybe someone has a good hint.
Thanky you all in advance,
regards
not sure about the dateTime issue, but check out indexes, indexing and custom index to figure out setting titles and description.
to set your title for instance
#indexer(IFormName)
def titleIndexer(obj):
return obj.valueFromForm
grok.global_adapter(titleIndexer, name="Title")
AFAIK, the problem is that DateTime field for dexterity types needs a datetime object, not a DateTime object.
In the invokeFactory, you should pass a datetime object instead of a DateTime object
>>>date=datetime.datetime(2011,1,1)
>>>myobj=target.invokeFactory(type_name="content_type_name", id=id, date=date)
>>from DateTime import DateTime
>>DateTime().month()
7
>>from datetime import datetime
>>datetime.now().month
7
>>datetime.now().month()
TypeError: 'int' object is not callable
>>> myobj.date
datetime.datetime(2013, 7, 26, 0, 0)
>>> myobj.date.month
7
>>> myobj.date.month()
TypeError: 'int' object is not callable
I'm currently working on some DateTime properties in a PropertyGrid in c#.Net. Im using the default drop-down datetime picker.
My question: Is there any way to show the full date with the time? By default the date is shown if no time is set, but I want zero-values aswell. I.e: I want "09.11.2009 00:00" to be shown instead of "09.11.2009".
Do I have to use some custom TypeConverter or Editor for this?
I feel so lost in this propertygrid and it makes me sad...
Any help would be appreciated! Thanks :)
Yes, you need your own TypeConverter. Derive it from DateTimeConverter and override the ConvertTo method. If you look this method in Reflector you will see this piece of code inside:
if (time.TimeOfDay.TotalSeconds == 0.0)
return time.ToString("yyyy-MM-dd", culture);
Just remove that for example.
Nicolas