how to add separator automatically in DayPickerInput component of react-day-picker - react-day-picker

how can i add the / - separator in DayPickerInput during the user digit?
for example in it locale: 23091989 digit should be equal to 23/09/1989

You can pass any formatter / parser to the formatDate or parseDate props:
http://react-day-picker.js.org/api/DayPickerInput#formatDate

Related

Drop timezone before format

I want to add one second to random time in ISO format, e.g.
var t = "2015-01-13T00:00:00+11:00";
moment(t).add(1, "second").format(); // expected "2015-01-13T00:00:01+11:00", but get "2015-01-12T18:00:01+05:00"
So it converts t to current browser timezone (+05:00 in my case) and only then adds a second.
How can I drop timezone before adding and return it after?
I found:
moment.parseZone(t).add("1", "second").format(); // "2015-01-13T00:00:01+11:00"

formatTime with “h” instead of “:” as separator

In France, we use the following 24 hour format for time: 18h30.
Therefore, I want to add the "h" char in the timeFormat option of FullCalendar 2.
I found an older post here:
formatTime with "h" instead of ":" as separator
but the solution is apparently not working anymore with FullCalendar v2.
Is there a way I could "escape" the "h" character in the timeFormat option ?
Fullcalendar uses Moment.js for date/times.
Escaping Characters:
To escape characters in format strings, you can wrap the characters in
square brackets.
moment().format('[today] dddd'); // 'today Sunday'
This works for the formatTime fullcalendar option too:
timeFormat: 'H[h](mm)'
Demo JSFiddle
You cannot escape it, however you can use the eventRender method to do the trick for you.
When the event is being rendered parse the DOM and replace the occurrence of : with h.
timeFormat: "H:mm",
eventRender: function(event, element) {
element.find('.fc-time').text(function () {
return $(this).text().replace(":", "h");
});
}

Flex 4.5 - How do you strip tags?

How do you strip (HTML) tags from a String in Flex 4.5 / 4.6?
I don't think there's an inbuilt function to strip the tags like in php.
However, you could use a regular expression to remove all text between < and >
var r:RegExp=/<\/??.*?\/??>/g;
I gotta run now, but if you could follow my line of thought:
While the string tests positive for the regexp, replace the occurrence with an empty string
That should remove all occurrences of this type:
<tag>
<tag />
</tag>
EDIT
var h:String="<html><head><title>Hello World</title></head><body><h1>Hello</h1>Hey there, what's new?</body></html>";
var r:RegExp=/<\/??.*?\/??>/s; //s=dotall to match . to newline also
while(r.test(h)) {
h=h.replace(r, ""); //Remember, strings are immutable, so you h.replace will not change the value of h, so you need to reassign the return to h
}
trace(h);
OUTPUT:
Hello WorldHelloHey there, what's new?

Specify DateTime format on zope.schema.Date on Plone

I'm working on a form with Formlib that looks like this:
from zope.schema import Choice, Float, Int, Date, TextLine
from Products.Five.formlib.formbase import PageForm
class ISimuladorForm(Interface):
"""
Zope Interface for the financial simulator for sofomanec.
"""
start_date = Date(title=_(u'Start Date'),
description=_(u'Loan start date.'),
required=False)
.
.
.
class SimuladorForm(PageForm):
form_fields = form.FormFields(ISimuladorForm)
The default input format for start_date is "mm/dd/yy", but users need to input the start_date in this format: "dd/mm/yy".
How do I change the default Date format for this Interface/Schema/Form?
You can use the DateI18nWidget instead of the default DateWidget.
It takes a displayStyle attribute that controls the formatting of the value, and it'll use the request locale to format the date. displayStyle must be one of 'full', 'long', 'medium', 'short', or None and refers to the date formats defined in zope.i18n; the default is None, which I think means 'short' but this is unclear from the code.
The exact formatting is taken from the request locale, which in turn is based on the language set for the Plone site by the portal_languages tool. Thus setting the language of the site also determines what date formats the DateI18nWidget will use; these are defined in the zope.i18n package in the locales/data directory, in a set of XML files (look for the <dateFormats> element).
If this isn't satisfactory then you'll have to create a custom browser widget. Your best bet is to subclass the DateWidget yourself and provide a new _toFormValue method to format the dates the way you want.
This might be helpful to add a custom date widget to your formlib form:
http://plone.org/documentation/manual/developer-manual/forms/using-zope.formlib/customizing-the-template-and-the-widgets
I suggest to write your own date widget by deriving from one of the existing
date widget classes:
http://svn.zope.org/zope.formlib/trunk/src/zope/formlib/textwidgets.py?rev=113031&view=markup
A custom conversion of the date format using the
_toFieldValue()
_fromFieldValue()
hooks is pretty easy...look at the existing code.
This is what I did:
from zope.app.form.browser import DateI18nWidget
from zope.i18n.format import DateTimeParseError
from zope.app.form.interfaces import ConversionError
class MyDateI18nWidget(DateI18nWidget):
displayStyle = None
def _toFieldValue(self, input):
if input == self._missing:
return self.context.missing_value
else:
try:
formatter = self.request.locale.dates.getFormatter(
self._category, (self.displayStyle or None))
return formatter.parse(input.lower())
except (DateTimeParseError, ValueError), v:
raise ConversionError(_("Invalid datetime data"),
"%s (%r)" % (v, input))
class SimuladorForm(PageForm):
...
form_fields['start_date'].custom_widget = MyDateI18nWidget

How to encode the plus (+) symbol in a URL

The URL link below will open a new Google mail window. The problem I have is that Google replaces all the plus (+) signs in the email body with blank space. It looks like it only happens with the + sign. How can I remedy this? (I am working on a ASP.NET web page.)
https://mail.google.com/mail?view=cm&tf=0&to=someemail#somedomain.com&su=some subject&body=Hi there+Hello there
(In the body email, "Hi there+Hello there" will show up as "Hi there Hello there")
The + character has a special meaning in [the query segment of] a URL => it means whitespace: . If you want to use the literal + sign there, you need to URL encode it to %2b:
body=Hi+there%2bHello+there
Here's an example of how you could properly generate URLs in .NET:
var uriBuilder = new UriBuilder("https://mail.google.com/mail");
var values = HttpUtility.ParseQueryString(string.Empty);
values["view"] = "cm";
values["tf"] = "0";
values["to"] = "someemail#somedomain.com";
values["su"] = "some subject";
values["body"] = "Hi there+Hello there";
uriBuilder.Query = values.ToString();
Console.WriteLine(uriBuilder.ToString());
The result:
https://mail.google.com:443/mail?view=cm&tf=0&to=someemail%40somedomain.com&su=some+subject&body=Hi+there%2bHello+there
If you want a plus + symbol in the body you have to encode it as 2B.
For example:
Try this
In order to encode a + value using JavaScript, you can use the encodeURIComponent function.
Example:
var url = "+11";
var encoded_url = encodeURIComponent(url);
console.log(encoded_url)
It's safer to always percent-encode all characters except those defined as "unreserved" in RFC-3986.
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
So, percent-encode the plus character and other special characters.
The problem that you are having with pluses is because, according to RFC-1866 (HTML 2.0 specification), paragraph 8.2.1. subparagraph 1., "The form field names and values are escaped: space characters are replaced by `+', and then reserved characters are escaped"). This way of encoding form data is also given in later HTML specifications, look for relevant paragraphs about application/x-www-form-urlencoded.
Just to add this to the list:
Uri.EscapeUriString("Hi there+Hello there") // Hi%20there+Hello%20there
Uri.EscapeDataString("Hi there+Hello there") // Hi%20there%2BHello%20there
See https://stackoverflow.com/a/34189188/98491
Usually you want to use EscapeDataString which does it right.
Generally if you use .NET API's - new Uri("someproto:with+plus").LocalPath or AbsolutePath will keep plus character in URL. (Same "someproto:with+plus" string)
but Uri.EscapeDataString("with+plus") will escape plus character and will produce "with%2Bplus".
Just to be consistent I would recommend to always escape plus character to "%2B" and use it everywhere - then no need to guess who thinks and what about your plus character.
I'm not sure why from escaped character '+' decoding would produce space character ' ' - but apparently it's the issue with some of components.

Resources