ember-pikaday losing a day - ember.js

I'm trying to use ember-pikaday, but I'm having issues with it not displaying the correct date. Every time the date it displays, its the previous date of the actual date. For example if the date is 04/06/2016, it displays 04/05/2016. Below is the code that I am using, I have noticed though that if I replace value with placeholder, then the date does display correctly, just not in the right format, i.e. 2016-04-06. What's going on here?
{{pikaday-input id="effectiveDate" name="effectiveDate" class="form-control textCenter" format="MM/DD/YYYY" value=model.effectiveDate firstDay=0 disabled=isDisabledDate}}

This is because it uses your local timezone by default when creating a new Date object. The addon supports working with UTC, try setting useUTC=true on the component.

Related

ISO 8601 string instead of datetime

I have faced this problem in other projects, but right now we're working in Django / Python with Vue.js and PostgreSQL.
Nearly every 'date' field in our model is truly a date, not a datetime. The business users don't care about a time-part, in fact storing any such value is misleading. A good example is the effective date on a tax rate. From the user point of view, it takes effect at midnight on the specified date.
If we store this as a Django DateTimeField or DateField, it requires a time-part. It could be 0000h, but the value has no meaning to the business, because they will never need to see or compare anything with the time-part. The Django functionality is great if we want to store a real datetime, put it into the database as UTC, and then display it to users in their local time through the automatic time zone conversion. But we don't. If the effective date is March 1, 2019, it should display as such regardless of the user's timezone. If the date is stored as a datetime (2019, 3, 1, 0, 0, 0) and entered by someone in Vancouver, it will appear as the next calendar day for another user in Toronto. Definitely not what we want. We could kludge it by setting the time-part to 1200h, but really?
We also have potential problems, depending on the internal representation in the database, when using SQL or tools that access the schema directly (e.g. BI tools). How do we know what time zone applies to the datetime value?
So, we're thinking of using Django CharField with ISO 8601 format (YYYY-MM-DD) instead. It will sort properly, it can be compared easily (or directly in some tools like SQL), and can be displayed without reformatting if the client is willing to use the standard. If we need to do date arithmetic, we can use the Python Standard Libraries datetime and calendar to convert from/to string. We'll need to use those to catch SQL injection attacks anyway.
We will also need to deal with date entry through a Datepicker, converting to the ISO 8601 string before storing and back again when displaying for edit.
It appears to be a better way to represent what the business needs, and it gets rid of any timezone conversion issues.
There is certainly a lot of comment on datetime and time zone handling, but I haven't found anyone taking this approach to storing true dates. Am I missing an important 'gotcha'? We're early enough in the project that we can go either way, so I'm hoping to confirm that this will work before refactoring becomes a big job.
Have you considered using DateField?
This will only store the date part and not the time.

Django datetime field fractional support

I have Django 1.9.5 installed with MariaDB 10.1.13 (also tested with MySQL 5.6.30) (which was updated from MySQL 5.5) and I am trying to get fractional seconds support in a date time field.
I have created a test model to try and get this working, here is the definition
class History(models.Model):
date = models.DateTimeField(null=True)
then in the shell I have run the following
History(date=datetime.now()).save()
and then when I query it
type(History.objects.get(id=1).date)
I get
<type 'NoneType'>
even though the entry appears in the database.
I can also use the field in a query
History.objects.all().order_by('date')
I know it works because inspecting the data shows that the order has changed
But I need to be able to return the date so I can compare it with another.
I was using the MySQL 5.5 without fractional support but there are records in my database that have the same datetime field and thus the order_by didnt work, I was using order_by id and that worked whilst the records were entered chronologically, but now this isnt the case I need fractional support.
Any ideas?
For this sort of situation it might be better to store the date and time as a unix timestamp in the database. There you millisecond accuracy. You can convert to python datetime objects at anytime with fromtimestamp.
Last but not least, you can easily convert unix timestamps with javascript to date times in the user's own timezone. A process that's far more complex with django or any other server side tech.

Django 1.6 filter by hour and time zone issue

In my application I use time zones (USE_TZ=True) and all the dates I create in my code are aware UTC datetime objects (I use django.util.timezone.now for the current date and the following helper function to ensure all the dates in my instances are what I expect:)
#classmethod
def asUTCDate(cls, date):
if not timezone.is_aware(date):
return timezone.make_aware(date, timezone.utc)
return date.replace(tzinfo=timezone.utc)
I also enforced the check of naive/aware dates using this snippet (like suggested in the doc):
import warnings
warnings.filterwarnings(
'error', r"DateTimeField .* received a naive datetime",
RuntimeWarning, r'django\.db\.models\.fields')
As I understood so far, this is the right way to proceed (this is a quote from the django documentation: "The solution to this problem is to use UTC in the code and use local time only when interacting with end users."), and it seems that my app is handling dates very well… but I have just implemented a filter against a model that makes use of the Django 1.6 __hour and it force the extraction based on the user timezone, the result is something like:
django_datetime_extract('hour', "object"."date", Europe/Rome) = 15
but this breaks my query, since some results I was expecting are not included in the set, but when I use a __range to search between dates it seems to work as expected (objects with a date in the range are returned)… so it seems to me that Django takes into account timezones in queries only for the __hour filter… but I don't understand why… I was supposing that UTC is used everywhere except in templates where the displayed dates are formatted according to user tz, but maybe that's not true.
So my questions are: is the way I'm working with time zones right? Is __hour filter wrong or what?
It seems as though you're doing the right thing with dates. However, all the documentation for any date related functionality, such as filtering by hour include this note:
When USE_TZ is True, datetime fields are converted to the current time
zone before filtering.
For the range filter, this note doesn't exist because range can be used to not only filter on dates, but other types as well such as integers and characters. ie It is not necessarily datetime aware.
In essence the problem comes down to this: where do you draw the line between 'interacting with users' where times are in a local timezone, and what is internal where times are in UTC? In your case, you could imagine a user entering in a search box to search for hour==3. Does that mean for example that your form code should do the conversion between hour==3 and the UTC equivalent? This would then require a special forms.HourField. Or perhaps the value (3) should be fed directly to the query where we know that we're searching on an hour field and so a conversion is required.
We really have to follow the documentation on this one.
Values which are going to be filtered against date/time fields using any of the specialised date/time filtering functions will be treated as being in the user's local time zone.
If using the range filter for dates no time conversions occur so you are expected to convert the user's entered local time value to UTC.

Oracle ApexCreate Time field HH:MM

I am having difficulty with a duration field on my form/table.
The users need to indicate in HH:MM how long a meeting took.
What datatype should the column have in the Table. Currently it is TIMESTAMP
How can I make the field have an input mask of 'HH:MM'. What I would like is for the user to be able to type '0130' and the field format it to '01:30' immediately.
Reporting on these times is required so I assume that entering the data as VARCHAR will not help.
Honestly, this is not such an easy subject as people might think it is, and probably more from a user interface point of view than technically.
The easiest way out? The apex datetimepicker. And honestly, if you're new to the technology I'd advise you to use this, especially if you want to steer clear from javascript/jquery initially.
Let's put it this way: the datepicker is fine and works good, but time is really not that fantastic.
Not all that hot right. The value in the input item does not change until you hit 'Close'. The time component seems like a last second sloppy addition honestly. It works, however. (But I'd still set the field to readonly so that a user can not enter text directly.)
Allowing text to be entered means it needs to be validated according to the correct format mask. And format masks differ between those in jQuery (the datepicker) and those in Oracle, and it might be possible that your oracle format mask is not possible in the datepicker, adding even more complexity. There is also no 'live' date validation (nor datetime), there is only the builtin item validation which will check the format mask and which fires on submit.
Anyway, I'd say take a look at it. Set your item to be displayed as a Date Picker, and use the format mask under settings to get the datetime picker:
Now you can push it further of course, though it'll cost some effort. There are several options though.
Personally, when I've implemented date+time I've always split the date from the time in 2 fields. 1 with the date component, and one with the time component, while keeping the item with the original value hidden (so 3 items total). I then use the datepicker on the date item, and use jquery timepicker plugins on the time item. On submit I then add the 2 values together and parse them in a date, and put this value in the original item again (to allow the standard processing to work on items with source set to database column).
One example of a timepicker is here, another one here. They're both not that hard to implement. They have good documentation too. I don't want to dive in the implementation of it here though, I advise you take a look at it first and see how much it scares you. (I'd set up an apex demo but am a bit pressed for time at the moment).
For example, using Trent's (second link) plugin:
put the js file in the apex images directory. I made a folder "/custom" in my case
add the required js files to the page (assuming apex 4.2, put this in javascript file urls)
#IMAGE_PREFIX#libraries/jquery-ui/1.8.22/ui/jquery.ui.slider.js
#IMAGE_PREFIX#custom/jquery-ui-timepicker-addon.js
use onload code such as this to initialize a field
$("#P95_DEPARTURE_TIME").timepicker({hourGrid: 4,minuteGrid: 10});
It'll end up looking as this:
Any further interaction between pickers will need to be handled in javascript code if you want it live. Don't forget server validations.
As for items, my hidden date item has format mask DD-MON-YYYY HH24:MI. Format masks are important, because items are bind variables, and bind variables are varchar2. The value in the html form is also just that, text.
For example, this is on my displayed date item, with a similar setup for the time item:
Then in an after-submit computation I glue the values together again and put them in the m that'll save the value to the database:
:P95_DEPARTURE_DATE_DISP||' '||:P95_DEPARTURE_TIME
This is just a short guide on the setup though, but might be interesting once you're a bit more familiar with the product.
There are also 2 timepicker plugins on apex-plugin, but honestly I don't find them interesting at all when compared to these already existing fine jquery plugins.
Give it some thought and look at it.
If quarters are enough..
item: text field with autocomplete
SELECT ss|| ':' || dd ss_dd
FROM
(SELECT to_char(trunc(sysdate)+(level - 1)/ 24,'HH24')ss
FROM dual CONNECT BY level <= 24),
(SELECT lpad(mod(15 * level, 60), 2, '0') dd
FROM dual CONNECT BY level <= 4)
APEX 4.2: Just to shed some light for any future viewings; now there are loads of Apex plugins for the purpose of picking Date/Time or both returning variations of date time formats as you would required. For e.g. as in your case HH:MM or HH24:MI.
I have personally used TimePicker plugin from http://www.apex-plugin.com which I have no problem in recommending.

Ember complex property bindings

I am using quite complex property bindings to be able to change either day, month or year of a user's birthdate. Having an attr birthDate of type date on a user and three properties for each piece of the date.
I am using moment.js to simplify date manipulations.
By trying the reduced showcase on jsfiddle you'll see that if you change year or day, the month is always increased by 1. I can't say what is happening. Just this: when setting the new date, the value is correct and gets changed later. Is there an issue with ember-data date attributes and some formating?
Again: here's the jsfiddle - written in CoffeeScript.
Thanks in advance!
I looked at your code and it looked like it should be working fine, the more I stepped through it the more I got annoyed that I couldn't spot the problem ... turns out it's the .month() method from Moment.js ... from the docs:
"Mutates the original moment by changing the month. Accepts numbers from 0 to 11"
Pretty dumb huh? In any case change your setMonth to subtract 1 from the value when you use .month()
setMonth: (property, value) ->
#set property, moment(#get(property)).month(value-1).format()
return value