Dateformat Rails 3.1 - ruby

I've been banging my head against the table for a while now trying to figure out how to get dates in the format of dd/mm/yyyy to be successfully saved to the database.
I'm using the latest version of Rails (3.1.1) and have added;
Time::DATE_FORMATS.merge!(:default => '%d/%m/%Y')
Date::DATE_FORMATS.merge!(:default => '%d/%m/%Y')
To my environment.rb file and have also download the en-AU.yml locale file and have set the locale correctly. In my model I have;
validates :invoice_date, :presence => true
But everytime I submit a form with a date in the format of dd/mm/yyyy (24/11/2011 for example), it always says "Invoice date can't be blank". If I remove that validation rule it saves a null value. What do I have to do to get this work?
Thanks in advance :)
UPDATE:
Form field code is:
<input id="invoice_invoice_date" type="text" size="30" name="invoice[invoice_date]">
It's really quite strange. It's a nil value if it's out of the range of a mm/dd/yyyy format, however the trace is showing the inputted date... I'm at a loss.

I would suggest that you use the i18n api: http://guides.rubyonrails.org/i18n.html. So you can set the default time format for the particular locale in the locale file: example: en.yml. That might work for you.

Related

Laravel Nova: Datetime with format and pickerFormat combined does not work

I got the fallowing date time field:
DateTime
::make('foobar')
->format('DD-MM-YYYY HH:mm:ss') // https://momentjs.com/docs/#/parsing/string-format/
->pickerFormat('d-m-Y H:i:S') // https://flatpickr.js.org/formatting/
->rules('required', 'date_format:Y-m-d H:i:s')
->firstDayOfWeek(1)
Momentjs does not recognise the date. I get a warning after changing the date in console:
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
It seems like momentjs is not getting the format? But I am clearly setting it in the nova resource and so it should get passed to vue, and so on? right?
Removing ->pickerFormat() allows me to save the date, but without displaying it the way I want in the picker.
I might be doing it completely wrong, so if someone could produce a working example of a DateTime filed with format and pickerFormat then that would be great as well.
edit:
Some more info. I re-transpiled Nova's using dev mode so I could poke around using Vue (chrome extension) tool.
I have also looked at the DateTime (vue) component without success. To bad it is closed source.
Use the package lathanhvien/novaofdatetime I just wrote recently. Hope it’s good to you!
Package link: https://packagist.org/packages/lathanhvien/novaofdatetime

Angular-formly clean error

I have two fields whose validation logic depends on each other. Sometimes field 1 raises a validation error, but modifying the value of field 2 should make the value in field 1 as a valid one. Any idea if there's a way to do that in Angular-formly?
For example, let's say I have a field called dateOne and another one is called dateTwo. dateTwo should come after dateOne. If I enter dateOne as 2016-08-29 and set dateTwo to 2016-08-28, my validator for dateTwo returns an error, saying dateTwo should come after dateOne. If I set dateTwo to 2016-08-30, the error will go away and my from becomes valid, which works fine. However, if user changes dateOne to 2016-08-20, my form is technically valid, but it still remains invalid as I need a way to remove the validation error from dateTwo and make the form valid.
I don't know which calendar you are using, if you are using bootstrap then it is very simple.
in dateOne textbox:
max-date="model.dateTow"
and in date two:
min-date= "model.dateOne"
Once you select the start date, end date calendar will disable all the dates before selected date,
Once you select the end date, start date calendar will disable all the dates after end date.
See the complete article

Server time in Joomla

Do you know of any way to check the current time in Joomla considering the selected time zone in global configuration?
I have been looking in administrator settings but did not see any single word about the current time.
You can use the following code:
$date = new DateTime();
$config = JFactory::getConfig();
$date->setTimezone(new DateTimeZone($config->get('offset')));
This does two things. The first line creates a DateTimeobject based on the current server time and timezone. The following two lines get Joomla's global configuration and change the timezone of out date object to that timezone.
You can then format the date to whatever format you like by calling $date->format('Y-m-d H:i:s');. You can replace the format specifier by whatever you need, a reference of possible formatting options can be found here: http://www.php.net/manual/de/function.date.php

CodeIgniter translate PHP date

I have a datetime stored in mysql as timestamp.
I then format the datetime using
$newdate = date('d M Y', strtotime($this->query->datetime));
My question is how do I translate the date using codeigniter builtin lang helper?
in the application language folder add a subfolder for the language you want to translate to. In that folder make a file called date_lang.php and handle all you date translations.
$lang['datefrom'] = "dateTo";
Another option for translation of dates is to use locale.
PHP will handle the date translations for you. Set the locale globally for the user.
setlocale(LC_ALL, 'en_UK.utf8');
In my current project, we use the locale to handle money and dates. We use CI language files to handle string translations

ASP.NET MVC3 datetime format

I have MVC3 project with Entity.
I have Data Annotation on DateTime property with DisplayFormat(DataFormatString="{0:dd/MM/yyyy hh:mm:ss}")
Controller with method which has entity as argument and calling view with same entity object, which displaying its date property.
So, I open browser and enter link http://site/entity/method?dateproperty=01/09/2012 01:02:03 (1 September 2012) and it displays 09/01/2012 01:02:03 (9 January 2012).
In view I'm using DisplayFor it's displaying like dd/MM/yyyy as I have a set DisplayFormat.
Problem is that it's reading like MM/dd/yyyy instead of dd/MM/yyyy, any solution?
P.S. I have tried globalization in web.config <sysmte.web> but didn't help.
I suspect the problem is that you haven't specified ApplyFormatInEditMode = true in your attribute, so it's parsing using the default format, but formatting with the format you're specifying.
I'm not an MVC dev by any means, but if you want the same format to be used in both directions, I believe you can just change your attribute to:
[DisplayFormat(ApplyFormatInEditMode = true,
DataFormatString="{0:dd/MM/yyyy HH:mm:ss}")]
Note that I've changed hh to HH, as I suspect you want a 24-hour format. I'd actually suggest using yyyy-MM-ddTHH:mm:ss (ISO-8601) as a less ambiguous format for the URL parameter - with a more user-centric display format, of course.

Resources