Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
SPOPS::Tool::DateConveUser)Contributed Perl DocumenSPOPS::Tool::DateConvert(3)

NAME
       SPOPS::Tool::DateConvert	- Convert dates	to objects to/from your
       datastore

SYNOPSIS
	# Class	configuration with date	convertion rule	and metadata

	my $spops = {
	   class	       => 'This::Class',
	   isa		       => [ 'SPOPS::DBI' ],
	   field	       => [ 'email', 'language', 'birthtime' ],
	   id_field	       => 'email',
	   base_table	       => 'test_table',
	   rules_from	       => [ 'SPOPS::Tool::DateConvert' ],
	   convert_date_field  => [ 'birthtime'	],
	   convert_date_class  => 'Time::Piece',
	   convert_date_format => '%Y-%m-%d %H:%M:%S',
	};
	SPOPS::Initialize->process({ config => { test => $spops	} });

	my $item = This::Class->fetch(55);
	print "Birthdate field isa: ", ref( $item->{birthtime} ), "\n";
	--> Birthdate field isa: Time::Piece

	# Format some other way

	print "Birthday	occurred on day	", $item->{birthtime}->strftime( '%j' ),
	      "which was a ", $item->{birthtime}->strftime( '%A' ), "\n";

	# When creating	a new object, just set the correct type	of object as
	# the field value

	my $newborn = This::Class->new({ email	   => 'foo@bar.com',
					 language  => 'en',
					 birthtime => Time::Piece->new });
	$newborn->save;

DESCRIPTION
       This SPOPS tool converts	data coming from the database into a date
       object, and translates the date object into the proper format before
       it's put	back into the database.

CONFIGURATION
       This tool uses three configuration fields:

       convert_date_field (\@)

       An arrayref of fields that will be converted.

       If not specified	or if empty no action will be taken.

       convert_date_class ($)

       Class for date object to	be instantiated. Supported classes are:

       o   DateTime (along with	supporting parse class
	   DateTime::Format::Strptime)

       o   Time::Piece

       o   Class::Date.

       If not specified, 'DateTime' will be used.

       convert_date_format ($)

       Format (in strftime format) for date conversions. All implementations
       will likely use this for	converting the object to a string. Some
       implementations (like Time::Piece and DateTime) will use	this for
       parsing the date	from the database into the date	object as well.

       If not specified, '%Y-%m-%d %H:%M:%S' will be used.

IMPLEMENTATIONS
       DateTime

       Uses the	DateTime::Format::Strptime and "convert_date_format" to
       translate the date from the database.

       Uses the	DateTime "strftime()" method from along	with
       "convert_date_format" configuration to translate	the date into a
       string.

       Time::Piece

       Uses the	"strptime()" method and	"convert_date_format" to translate the
       date from the database.

       Uses the	"strftime()" method along with "convert_date_format"
       configuration to	translate the date into	a string.

       Class::Date

       Uses the	"new()"	method to translate the	date from the database.

       Uses the	"strftime()" method along with "convert_date_format"
       configuration to	translate the date into	a string.

TO DO
       If necessary, make this a factory and refactor if clauses into
       subclasses for the different implementations.

SEE ALSO
       DateTime

       DateTime::Format::Strptime

       Time::Piece

       Class::Date

AUTHOR
       Chris Winters <chris@cwinters.com>

perl v5.32.1			  2004-02-26	   SPOPS::Tool::DateConvert(3)

NAME | SYNOPSIS | DESCRIPTION | CONFIGURATION | IMPLEMENTATIONS | TO DO | SEE ALSO | AUTHOR

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=SPOPS::Tool::DateConvert&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help