Date validation

Author Message

Alejandro Serrano

Wednesday 27 September 2006 8:36:28 am

This may be a very simple task or already been documented, but I can't find any doc about it.
I have a 'event' class with 'event_start' and 'event_end'. I need to validate that event_end is >= event_start.
Is there any way to do it?

Nate Parsons

Wednesday 27 September 2006 12:59:23 pm

I was unable to find any "eZPublish" way of doing this sort of validation, I ended up using javascript to validate the two form fields & modifying my form's action:

<b>The Form Action</b>

action={concat("/content/edit/",$object.id,"/",$edit_version,"/",$edit_language|not|choose(concat($edit_language,"/"),''))|ezurl}>

<b>Javascript Example Code</b>


if(endUnixtime <= startUnixtime){				
		expMenu('error_start_end_date','show');
		expMenu('error_display','show');
		return false;
	}
	else{
		if(endUnixtime > startUnixtime)
			expMenu('error_start_end_date','none');		
		//Make sure that the end date is later than today
		var endDate = new Date(yy,(mm-1),dd);
		var today = new Date();
		var year = today.getFullYear();
		var month = today.getMonth();
		var day = today.getDate();
		var today = new Date(year,month,day,00,00,00);
		var dateDiffDays = parseInt((endDate - today)/(1000*60*60*24));
		if(dateDiffDays <= 0 ){
			//alert('The end date must be later than today\'s date.');
			//alert('Error2: dateDiffDays: '+dateDiffDays);
			expMenu('error_end_today_date','show');
			expMenu('error_display','show');
			return false;
		}
		else{
			expMenu('error_end_today_date', 'none');
			return true;
		}
        }
}
function datetounixtime(yy,mm,dd,hh,min,sec){
	var humDate = new Date(Date.UTC(yy,(mm-1),dd,hh,min,sec));
	return (humDate.getTime()/1000.0);

---------------------------------------------------------------------------------
I look forward to an America which will not be afraid
of grace and beauty.

-------------JFK 10/26/63------------------------------------------------

Kristof Coomans

Tuesday 03 April 2007 6:27:48 am

There's now a hack in progress which allows to add several kinds of custom validation when storing an object: http://projects.ez.no/objectvalidation

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 11:25:58
Script start
Timing: Jan 18 2025 11:25:58
Module start 'layout'
Timing: Jan 18 2025 11:25:58
Module start 'content'
Timing: Jan 18 2025 11:25:59
Module end 'content'
Timing: Jan 18 2025 11:25:59
Script end

Main resources:

Total runtime0.7770 sec
Peak memory usage4,096.0000 KB
Database Queries59

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0066 587.7813152.6094
Module start 'layout' 0.00670.0041 740.390639.3984
Module start 'content' 0.01080.7648 779.7891575.8906
Module end 'content' 0.77560.0014 1,355.679712.2031
Script end 0.7769  1,367.8828 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.4110160.0002
Check MTime0.00130.1688160.0001
Mysql Total
Database connection0.00090.116710.0009
Mysqli_queries0.727093.5729590.0123
Looping result0.00070.0843570.0000
Template Total0.740795.320.3703
Template load0.00210.273120.0011
Template processing0.738595.053120.3693
Template load and register function0.00020.031710.0002
states
state_id_array0.00140.182410.0014
state_identifier_array0.00090.120420.0005
Override
Cache load0.00180.2306160.0001
Sytem overhead
Fetch class attribute can translate value0.00070.087330.0002
Fetch class attribute name0.00140.183050.0003
XML
Image XML parsing0.00270.341330.0009
class_abstraction
Instantiating content class attribute0.00000.001450.0000
General
dbfile0.00230.2977230.0001
String conversion0.00000.001440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 14
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs