I have this domain class:
class activity {
String name
Date startDate
Date endDate
static constraints = {
}
}
What i want to do is:
a) apply constrains to the dates, for example minimum date and maximum date
b) in my project i need to have an Array of dates and add as many endDates as i want. is it possible to do so? and how
a) apply constrains to the dates, for example minimum date and maximum date
Here's an example of a minimum and maximum constraint applied to the startDate field
class activity {
String name
Date startDate
Date endDate
static constraints = {
// date must be between today and today + 7 days
startDate(min: new Date(), max: newDate() + 7)
}
}
A good reading of the Grails docs would answer a lot of the questions you've been asking here.
a) Adding Custom Validation to a Field
b) If I understand you correctly, what you might want to do is create another class called something like ActivityEndDate and then build your domain like this:
class Activity {
// regular properties
static hasMany = [endDates:ActivityEndDate]
}
Again, the docs are helpful here.
Related
I'm building a time extension (hours/minutes/seconds) for angular material DatePicker (beause there aren't any good ones out there yet). The problem is when I update the time in the time component I use the DatePickers select method which is the only method to set dates programatically using a Date object.
The problem is Datepickers inner select function does not consider different Hours/Minutes/seconds as a different date, and when supplied with such scenarion it will not update its inner workings.
The following is the select function of Angular Material Datepicker:
MatDatepicker.prototype.select = function (date) {
var oldValue = this._selected;
this._selected = date;
// this will eveluate as false since only hours/minuts/seconds are different and not day/month/year
if (!this._dateAdapter.sameDate(oldValue, this._selected)) {
this._selectedChanged.next(date);
}
};
Inside the sameDate method they use a method called compareDate which check the two dates only by day and month & year:
DateAdapter.prototype.compareDate = function (first, second) {
return this.getYear(first) - this.getYear(second) ||
this.getMonth(first) - this.getMonth(second) ||
this.getDate(first) - this.getDate(second);
};
This means select method will not emit the new date to DatePicker's inner components & parts.
I am using a custom NativeDateAdapter and a custom MatDateFormats but since the above check want emit the new date these mechanism want be reached.
P.S
Everything works ok when the updated date has a different day/year/month including the custom time formating to include the time parameters.
I resolved this by simply re-implementing the base classes compareDate method using the custom NativeDateAdapter.
export class AppDateAdapter extends NativeDateAdapter {
format(date: Date, displayFormat: Object): string {
// format your dates
}
compareDate(first: Date, second: Date) {
// compare first/current date with second/previous date
// you can implement your logic here.
return 1;
}
}
I used FSCalendar(https://github.com/WenchaoD/FSCalendar) in my project. If user click repeat button, the events repeats everyday. I want to show it on calendar which is in my application. How can I do it?
If you want to select date then below method will be helpful,
where calendar is outlet of FSCalendar.
calendar.select(calendar.today)
And if you want to select multiple dates then the best way would be to use event dots, and that can be possible through below delegate method of FSCalendar Data source,
func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int
{
//number of dots you want to show
}
or if you really want to show dates selected, you can use below method smartly and returning different colours for dates that you want to select,
public func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, fillDefaultColorFor date: Date) -> UIColor?
{
if your date
{
//return the colour for your dates
}
else
{
//return default colour
}
}
Hope, this answer helps you.
For Remainder app you need to do or use following thing.
1.Realm or Core Data - for Data persistency.
2.local notification - to notify user that some event is occured.
you need to use UILocalNotification that have one property fireDate property.
I don't know how you're persisting that information (the scheduled date), what i can tell you is that you can easily add a dot (or more if you'd like, just change the number) with the following delegate:
`func calendar(calendar: FSCalendar, numberOfEventsForDate date: NSDate) -> Int {
let formatter = NSDateFormatter()
formatter.dateFormat = "MM-DD"
let date1 = formatter.stringFromDate(yourDate)
let date2 = formatter.stringFromDate(date)
return date1 == date2 ? 1 : 0
}`
This method is one of FSCalendar delegates and it iterates all days in the current month (each one of them represented in date variable). In the example above i'm comparing if the any given date is equal to yourDate variable which has to be a NSDate as well by transforming both of them into Strings via NSDateFormatter in Month-Day format so the comparison is equal for all months. If true, return 1 (this indicates 1 dot, you may change it for more if you want to), otherwise return 0 dots below the specific date.
This code is Swift 2.3 compliance.
I'm attempting to create a filter on the view that allows users to filter the data by time ranges:
When users select this, it maps to an enum type TimeRange that contains two date objects. These date objects contain just the respective times, called lowerBound and upperBound respectively. For example:
MIDNIGHT_TO_SIX(1, Date.parse("HH:mm:ss", "00:00:00"), Date.parse("HH:mm:ss", "06:00:00")
This makes a Date object. Because I have not specified the date portion, that is set to epoch date. When I use these in a critieria for filtering:
and {
or {
eq('startDateTime', range.lowerBound)
gt('startDateTime', range.lowerBound)
}
or {
eq('startDateTime', range.upperBound)
lt('startDateTime', range.upperBound)
}
}
Nothing is being returned! This is clearly because none of the dates in my database are before or equal to epoch time, as per the last or closure.
Is there a way of telling the criteria to only use the time portion during the comparison, or is there a way that I can declare lowerBound and upperBound to not be concerned with the Date?
the straight-forward approach would be to save the number of seconds (or millis) from 00:00:00, so that the lookup is as easy as:
enum Range {
MIDNIGHT_TO_SIX( 1, 0, 6 * 60 * 60 ) //in seconds
}
criteria:
{
between 'startInSec', range.lower, range.upper
}
I would like to show a series of financial transactions in a TableView.
Each Transaction consists of a Date, a Description and an Amount.
I can make this work using bindings if I treat all the cells as Text using the example shown in a reply to another question. This allows in cell editing which is my goal.
But I can't get it to work on the date and amount columns, I think I need a separate cell factory for each cell type and a possibly a separate updateItem method but I'm stuck.
Any pointers to an example or suggestions would be helpful.
You may want to check out the DataFX project at:
http://www.javafxdata.org/
and specifically the cell factories like:
http://www.javafxdata.org/javadoc/org/javafxdata/control/cell/TextFieldCellFactory.html
DataFX contains custom cell factories for several data types, tables, lists and tree views. Assuming that for example your amount has a double type, you could write something similar like that in a subclass of TableColum
(replace ??? by the class name of the class that represents a row in your table):
setCellFactory(TextFieldCellFactory.<???, Number>forTableColumn(new Callback<String,Number>(){
#Override
public Number call(String newValueStr) {
double newValue = Double.parseDouble(newValueStr);
return newValue;
}));
setOnEditCommit(new EventHandler<CellEditEvent<???, Number>>() {
#Override
public void handle(CellEditEvent<???, Number> t) {
double newValue = t.getNewValue().doubleValue();
// do something with the double value the user entered here
}
});
}
}
I hope that at least gives you some direction. I have left out Exception handling for clarity.
I am following This Blog to add a calendar component in my application. Now I want to select more than one dates to show some report for selected dates.
How can I do that ?
Thanks
For this purpose in this tutorial tappedTile method is use for selection of date.so for selecting a number of dates you need to make array and add all the strings.
use like this
NSMutableArray *eventArray//your array for adding dates,make it propeerty and alloc it.
- (void)calendarView:(KLCalendarView *)calendarView tappedTile:(KLTile *)aTile{
int month;
month=[aTile.date monthOfYear];
int day;
day=[aTile.date dayOfMonth];
int year=[aTile.date yearOfCommonEra];
NSString *dateForCompare;
dateForCompare=[NSString stringWithFormat:#"%i/%i/%i",month,day,year];
[eventArray addObject:dateForCompare];
//use this array (having dates in string format).
// use this by using your logical capability
}
see this link,may be it helps you