Setting permitted range to DateField in Flex? - actionscript-3

I have a Flex screen (MXML) with two date fields (say, From and To date). Based on the date values, data has to be shown on the DataGrid. Here, I have to restrict the user on choosing the date value. A permitted range has to be set in the date field.
Eg, The default date for both date fields is "Today"
The permitted range for From Date is "Today - 7 to Today"
The permitted range for To Date is also "Today - 7 to Today"
How can I achieve this? Both by selecting the date picker as well as by entering the date value if the date field is set to editable

I would simply implement a custom DateValidator for this kind of logic especially that users can also type-in certain dates in invalid or not supported format.
ActionScript (pseudo-code):
public class RangeDateValidator extends DateValidator
{
[Bindable]
public var fromDate:String;
protected override function doValidation(value:Object):Array
{
// create a real date and apply your custom logic
// based on the fromDate value
}
}
MXML (pseudo-code):
<d:RangeDateValidator source="{ toDate }" property="text"
inputFormat="DD.MM.YYYY" fromDate="{ fromDate.text }" />
Let me know if this is working in your case

Related

to change the date format in data base

it is not able to store day,month,year in the format of dd/mm/yy in data base by getting value through the form of Yii.it is only possible to store in the format of year/month/date can any body answer.
Your question is not clear. I am guessing when you save date submitting the form it saves in mysql default format and then when you display it, it is not displayed in your desired format. If this is the case, I would recommend the best way to solve this is to change the date format in the model. You can use the 'before save' and 'after find' methods in the model to change the date format before saving to db and also change it when it is pulled from db. The actual date format will remain the same in db, but it will also display in the format you want it to. Here's an example,
protected function beforeSave()
{
if($this->date!=null){
$this->date=date('Y-m-d', strtotime($this->date));
}
return TRUE;
}
public function afterFind()
{
if($this->date!=null){
$this->date = date('d F Y',strtotime($this->date));
}
return true;
}

Laravel 4.1 - display time format from mysql column TIME

I have a column in mysql database named time_start which type is TIME.
I am trying to format the displayed time in my view from H:i:s to simple H:i, so instead of 20:00:00 i will get 20:00.
Firstly i thought i can use format() method, but it's supposed to be used with timestamps, so of course i get error Call to a member function format() on a non-object.
I'm sure it's a simple question, but i can't solve this.
-EDIT-
Forgt to mention. I am working with a many to many relationship and i'm calling my data like:
$schedule->time_start
Here i would like to show the time in H:i format, not H:i:s.
Have you tried an accessor method? I.e. in the Schedule model,
/**
* Return a truncated version of the timestamp.
* #param $value original value of attribute
* #return string truncated value
*/
public function getTimeStartAttribute($value)
{
// Input is HH:MM:SS
return substr($value, 0, 5);
// Output is HH:MM
}
Then $schedule->time_start ought to return the time in HH:MM format.

how to save object with sysdate functionality

i have an object student. then there is a property called expiry date. this is need to be set with the database sysdate + a value(1000).
so how can i save with jpa. can't i do it on the jpa prepared statement query itself?
if i use sql.date is it exactly give the same value as when we are saving as 'sysdate'?
can't i do it with on the query itself?
other properties can be set to the object. but the problem is this expiry date as it needs the sysdate and add another value to it eg: expiry date = sysdate + 1000; how can i do it with jpa prepared statements. please reply me
What about use a seperate query to retrieve sysdate and set it to your object.
I usally create a Clock to handle this:
public interface Clock {
Date now();
}
public class HibernateClock implements Clock {
//use query to retieve the db sysdate
}
You can add it in java itself. Use calendar object to add days.
Calendar expirydate=Calendar.getInstance();
expirydate.add(Calendar.DATE, 1000);
then
expirydate.getTime() will give you expire date object.
Why do you want to use sysdate? Its syntax is database specific and also dependent on the DB-hosting machine's clock, rather than on your application-hosting machine's clock.
Easiest way is to use java.util.Date as the expiryDate's type and the value of new Date(System.currentTimeInMillis() + 1000). Use this value in the field's declaration for featuring it as default value on new Student creation or use it as the value passed to the setter when modifying an existant Student.
public class Student {
...
/**
* Using java.util.Date here. Hibernate knows to convert it automagically to java.sql.Date.
* Set default value to current time + 1 second, if this is your requirement.
*/
private Date expiryDate = new Date(System.currentTimeInMillis() + 1000);
public void setExpiryDate(final Date expiryDate) {
this.expiryDate = expiryDate;
}
...
}

Setting the date in an HTML5 date input

I'm trying to progamatically set the date in an HTML5 date input using ajax and javascript. I have an ajax/php call that returns the date that I want in a string variable in the format "YYYY-MM-DD". I can't seem to make this work. Here is my attempt:
var myDate = "2013-07-10" //actually is returned by my ajax call, but same idea
//set the date value
var thisDate = new Date();
thisDate.setFullYear(parseInt(workout_date.split("-")[0]));
thisDate.setMonth(parseInt(workout_date.split("-")[1])-1);
thisDate.setDate(parseInt(workout_date.split("-")[2]));
document.getElementById("date_input").value = thisDate;
I'm not getting any errors, but my date input just remains at the default (mm/dd/yyyy). Anyone know what I am doing wrong? Thanks!
You're trying to set the value of the date to a Date object. But the date input, like other inputs, can only accept strings:
If the user agent provides a user interface for selecting a date, then the value must be set to a valid date string representing the user's selection. [Emphasis added.]
In this case, myDate represents a valid date string, so you can use it directly.

DateField: selectedDate shows hours as 24:00:00

With a DateField component, the selectedDate.getHours returns as 24:00:00. I want it to return as 00:00:00.
Is there an easy way to do this?
Thanks!
UPDATE:
First, I set a variable in my Model that equals the selectedDate of a DateField component:
model.generalInfo.endDate = endDate_df.selectedDate;
Then I set another variable based on that value and I trace it out:
param.todate = df.format( model.generalInfo.endDate.toString() );
And this is where I see the time equal to 24:00:00
you could try something like
selectedDate.time = selectedDate.time - 24 * 60 * 60 * 60 * 1000
as a Date.time represents miliseconds since 1970 or whatever.. you substract 24 hours..
if it not works for you, you can create a new function or getter that converts it, or you can create a new mxml module, with DateField as superclass, and you can override the getHours method. tons of options to do this..
It looks like you are using the Flex DateFormatter to format the Date object. Have a look at the docs for this class, it has a formatString property that you can use to control how to output the date (or in this case the time).
If you give the DateFormatter a format string that contains "H" will output the hour in 24 hour format using the number range 1-24. If the format string contains "J" it will output the hour in 24 hour format using the range 0-23.
To get your desired output, use "JJ" in the format string, in addition to any other items. For example to output the hours, minutes, seconds:
var someDate:Date = new Date(2012, 11, 5);
var df:DateFormatter = new DateFormatter();
df.formatString = "JJ:NN:SS";
var formatted:String = df.format(someDate); // 00:00:00
Also, as #Flextras mentioned, there is Flash localization API you can use which has the added benefit of converting date/time strings to the values used by their locale. These are the DateTimeFormatter classes:
fl.globalization.DateTimeFormatter
spark.formatters.DateTimeFormatter (Flex 4)
These classes format dates into the user's locale (or one that you specifcy), and format Date objects the same way the DateFormatter does.