Angular 2 Date Pipe handling offset when none exists - date

I have some code that processes a date string and I want to display it on the UI using the date pipe. Here is a sample value of the date
"2017-02-07T21:23:19.163"
And here is the template code
<div class="input-group" *ngFor="let history of selectedPricingItem.history">
<span class="input-group-addon">
<i class="fa fa-fw fa-calendar-o " aria-hidden="true">
</i>
{{history.createdDate| date:short}}
</span>
<textarea class="form-control" [(ngModel)]="history.generalNotes" rows="2" readonly></textarea>
</div>
Here is date that is put on the UI
2/7/2017, 5:23 PM
For some reason it is adding an offset when there is no offset in the string. Do I need to convert it to a date object with moment or something first?
I am using "#angular/common": "^2.2.0" in my package.json

This happens b/c DatePipe expects the supplied date to already have a timezone offset, and if none is specified then it assumes that the offset is "+0" (UTC). It then attempts to convert the date to the client's local offset. You must be UTC-6 (Central Time), hence why it's subtracting 6 hours. Someone on Eastern or Pacific time would see a different time than what you see.
Not sure what backend you're using, but mine is C#/WebApi, and my solution was to find DateTime objects where the Kind property equals "UnSpecified" and change it to either "UTC" or "Local", as appropriate, that way the date gets JSON-serialized with a timezone offset and eliminates confusion.
An alternative solution if you don't like this behavior is to replace DatePipe with your own custom pipe and use something like moment.js to handle the date parsing (DatePipe uses the Internationalization API by default).

Related

How can one disable future dates from the current date and also disable dates 1 month before the current date using Blazor?

Using Blazor date input how can you disable future dates from the current date and also disable dates 1 month or more before the current date? But display the current date when page loads.
I'm using Blazor-Server-Side.
So far I have the razor page set like this:
<InputDate #bind-Value="viewmodel.Date" class="form-control" id="date"></InputDate>
<label> The date </label>
<ValidationMessage For="() => viewmodel.Date" />
And the model like this:
[Required(ErrorMessage = "Select the date")]
public DateTime Date { get; set; } = DateTime.Now;
I have tried 'max' attribute in the input tag to leave an end date but it did not work. I could not find a method to do this. Please let me know how I can solve this in Balzor or if there are other ways to achieve the same results? I would prefer if no jquery was used.
Thanks for your help.
If you are happy to do it in the markup, you can use min and max
<input type="date" min="2021-11-01" max="2022-01-31"/>
This example restricts to dates between 1st November 2021 and 31st Jan 2022 - the format yyyy-MM-dd is important in min/max.
You can use variables for the dates in Blazor, but make sure to format them using yyyy-MM-dd.
<InputDate #bind-Value="viewmodel.Date"
class="form-control"
id="date"
min=#DateTime.Today.AddMonths(-1).ToString("yyyy'-'MM'-'dd")
max=#DateTime.Today.ToString("yyyy'-'MM'-'dd")
/>
Blazor Repl - Working Sample

Convert data in TYPO3 fluid form

I need yours help. I have follow form:
{namespace femanager=In2code\Femanager\ViewHelpers}
<div class="femanager_fieldset femanager_membershipend control-group">
<label for="femanager_field_membershipend" class="control-label">
<f:translate key="tx_feusersplus_domain_model_user.membershipend" default="Expiration date of the membership"/>
</label>
<div class="controls">
<femanager:form.textfield
disabled="true"
id="femanager_field_membershipend"
property="membershipend"
class="input-block-level"
additionalAttributes="{femanager:Validation.FormValidationData(settings:settings,fieldName:'membershipend')}"
/>
</div>
</div>
And it get date in the next format - 1493942400. How I can make good look for date ? Thank you for advice!
Your property seems to be declared as integer (unix timestamp) in the model.
You can change the field to the following:
<femanager:form.textfield
disabled="true"
id="femanager_field_membershipend"
property="membershipend"
class="input-block-level" value="{yourModel.membershipend-> f:format.date(format: 'd.m.Y')}"
additionalAttributes="{femanager:Validation.FormValidationData(settings:settings,fieldName:'membershipend')}"
/>
This will format the property to a readable Date. But after that you will get problems saving the property correctly. If the property is really an integer, you need to write a converter for converting the date to an unix timestamp. It must work like here just in the reverse and I think TYPO3 does not have the correct converter for your needs out of the box.
I recommend you to change your property to DateTime (including the database field). Then you can use the DateTimeConverter of TYPO3 to save the data correctly.
EDIT: In your case the field is disabled="true" which should mean that the data will not become submitted. In that case you should not get problems with converting after submitting the form.

Bootstrap 3 input Date format

I would like to know without using any plugin/library, is it possible to format bootstrap date input format.
My webservice will return ISO.DATE pattern = "yyyy-MM-dd", and bootstrap displays it in MM/DD/YYYY format. I want to change it to DD/MM/YYYY format.
Is it possible to do ? I googled and every one seem to be using some library. Since my requirement is simple, I do not want to use any library. Or do you think a library is required.
Any help is appreciated.
<div class="form-group">
<label for=displayFrom class="col-md-3 control-label"> Date </label>
<div class="col-md-4">
<form:input type="date" class="form-control" path="displayFrom" id="displayFrom"
placeholder="display From"/>
</div>
<div class="col-md-5 iserror">
<form:errors path="displayFrom"></form:errors>
</div>
</div>
You are using HTML5's date input which uses the YYYY-MM-DD format, which is unchangeable right now. Chrome and Opera uses the local computer's locale to set the format of the input, Firefox and IE uses the default YYYY-MM-DD.

Date Select Error in Ektron

I have a form that is using the calendar/date selection tool within Ektron, but when users select the current date (or any date, for that matter), it gives an error saying that you need to select a date in the past.
We haven't tooled around in the code for this form, but it almost sounds like a validation issue.
Here's the code, as is, from Ektron.
<p align="center" style="text-align: left;">Date program was presented: 
<ektdesignns_calendar title="Date presented" id="Date_presented" onblur="design_validate_xpath('number(translate(.,\'-\',\'\')) <= number(translate($currentDate,\'-\',\'\'))',this,'Date in the past (required)');" ektdesignns_name="Date_presented" ektdesignns_caption="Date presented" ektdesignns_invalidmsg="Date in the past (required)" ektdesignns_validate="xpath:number(translate(.,'-','')) <= number(translate($currentDate,'-',''))" ektdesignns_basetype="calendar" ektdesignns_datatype="date" ektdesignns_validation="datePast-req" name="Date_presented">
<input type="text" size="30" readonly="readonly" unselectable="on" />
<img width="16" height="16" class="design_fieldbutton" alt="Select date" src="[skinpath]btncalendar.gif" unselectable="on" /></ektdesignns_calendar></p>
My knowledge on validation is limited, but it looks like it's parsing the date as an integer. Is it possible to add a day (+1) to the current date so that it interprets any day as valid as long as it's not in the future?
I guess this is a HTML form as opposed to a Smart form?
If so, have you checked the validation settings on the calendar field? If you edit the form, right-click on the field and choose Field Properties you will get the properties window. Go to the Validation tab and check the setting in the Validation drop down.
There are options for ensuring the date is in the past or the future. Perhaps one of these options has been set?

Validate range of dates with Regula

Is there any way to use #Range to validate a range of dates in Regula? (ditto #Min and #Max)
Or do I need to use #Custom?
#Range(min=
and
#Range(max=
do not seem to accept anything of the type Date - only numbers or strings.
Unfortunately #Range only accepts numbers. I think you can do something like this though:
<input type="hidden"
name="date"
id="date"
data-constraints="
#Future(date='2000/1/1', format='YMD')
#Past(date='2010/1/1', format='YMD')"
/>
This ensures that the date is after 2000/1/1 and before 2010/1/1 (i.e., in between). I didn't document the date parameter because I don't think I had implemented it when I wrote the documentation. Sorry; the documentation is a bit behind because I'm working on rolling version 1.3 of Regula out, that will have a lot more goodies. I'll be getting started on updating the documentation soon!
I found that the following hack works:
I added a second, hidden input that contains the date entered in the format of Date.getTime():
<input type="hidden" data-bind="value: myDateValue.getTime()" ... />
(I'm using Kendo MVVM, but I'm sure other MVVM libraries can handle the same approach)
Then for the constraint, on server side (ASP.NET MVC in my case) I'm generating the Unix time for the min and max:
#Range(min="<%= (dateTime1 - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds %>",
max="<%= (dateTime2 - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds %>")
EDIT
Need to use .TotalMilliseconds - and even so there's some unexplained discrepancy.