Tangra...ndDate(3pm)

πŸ“¦
version 2.12 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Tangra...ndDate β€” the manual, but make it cute ✨

okay bestie, so this whole page is literally called Tangram::Type::TimeAndDate, and it lives in the User Contributed Perl Documentation section (section 3pm, for the record πŸ‘‘). No cap.


πŸŽ€ NAME πŸŽ€

Tangram::Type::TimeAndDate β€” it maps date & time fields. that's the whole job. slay.


✨ SYNOPSIS ✨

use Tangram;

# any of:
use Tangram::Type::Date;   # RAW - use with caution
use Tangram::Type::Time;
use Tangram::Type::Date::Cooked;   # pure ISO-8601
use Tangram::Type::Date::DateTime;
use Tangram::Type::Date::Manip;
use Tangram::Type::Date::TimePiece;

Tangram::Schema->new(
   classes => {
       NaturalPerson => {
          fields => {
              rawdatetime => [ qw( birth death ) ],
              rawdate => [ qw( depart return ) ],
              rawtime => [ qw( breakfast lunch dinner ) ],
              cookeddatetime => [ qw( cooked ) ],
              dmdatetime => [ qw( datemanip ) ],
              timepiece => [ qw( fob ) ],
              datetime => [ qw( bloat ) ],

like yes, that block genuinely ends there, no closing braces, it's giving "I left you on read" energy πŸ™ˆ. copy it exactly, don't @ me.


🌸 DESCRIPTION 🌸

so these classes? their whole main character job is mapping strings over to SQL date or time types. big responsibility, they eat every time πŸ’….

Important bestie: these classes are not imported by Tangram.pm. not even a little. so you literally have to import them yourself with a use directive. no auto-magic, no freebies.

The three typetags rawdate, rawtime, and rawdatetime exist for mapping strings over to SQL date/time types β€” specifically for databases that actually differentiate between "dates" and "times". and what does 'Raw' mean? it means Tangram doesn't even try to interpret your strings. it's not nosy. it just passes them straight down to DBI and lets DBI deal. periodt. ✨

<candy>cookeddatetime</candy> is like rawdatetime except the date gets converted from the DBMS format into ISO-8601, in exactly this form:

YYYY-MM-DDTHH:MM:SS

for example:

2004-12-25T13:14:15

Other modules then take that ISO date and cook it even further into an object, following whatever the convention is for that particular module. lowkey iconic chain of custody 🧚.

⚠️ but heads up β€” this only works with back-ends that allow per-connection settings for the default date format. like, for example, Tangram::Driver::Oracle. if your back-end doesn't do that, this isn't it.

On the way back out? the date gets converted back into the DBMS format. and how? via vendor-specific functions mentioned over in Tangram::Relational. iykyk. πŸ”₯


πŸ¦‹ the persistent fields πŸ¦‹

The persistent fields can be specified either as a hash or as an array of field names. both are valid, pick your vibe.

In the hash form, each entry is a field name plus an associated option hash. that option hash may contain the following fields:

  • col
  • sql

col sets the name of the column used to store that field's value. it's optional β€” if you don't say anything it just defaults to the persistent field name. override it if your field name isn't an acceptable SQL column name (we've all been there πŸ’€).

sql sets the SQL type of the column. this is the one Schema::deploy() uses when it's initializing a database. and the defaults? okay so:

  • 'VARCHAR(255) NULL' for strings
  • 'INT NULL' for ints
  • 'REAL NULL' for reals

The persistent fields can also be specified as an array of strings, in which case the defaults are used. simple. clean. no thoughts head empty ✨


aaaand that's the whole page bestie, you understood it, you ate it, I'm obsessed πŸ«ΆπŸ’– this was Tangra...ndDate(3pm) from User Contributed Perl Documentation, perl v5.36.0, dated 2022-10-16 β€” go forth and map those date & time fields, queen πŸ‘‘πŸŒˆ

πŸ“¦ where this page comes from