SlideShare una empresa de Scribd logo
1 de 50
Descargar para leer sin conexión
Dates and Times
                             The Silent Killers
Saturday, August 11, 12
Dates and Times Are Easy!




Saturday, August 11, 12
Dates and Times Are Easy!


          • 60 seconds in a minute, 60 minutes in an hour.




Saturday, August 11, 12
Dates and Times Are Easy!


          • 60 seconds in a minute, 60 minutes in an hour.
          • 24 hours in a day, 365 days in a year, unless the year
                is a multiple of 4.




Saturday, August 11, 12
Dates and Times Are Easy!


          • 60 seconds in a minute, 60 minutes in an hour.
          • 24 hours in a day, 365 days in a year, unless the year
                is a multiple of 4.

          • Simple, right?


Saturday, August 11, 12
WRONG
Saturday, August 11, 12
A reality check




Saturday, August 11, 12
A reality check


          • There are not always 60 seconds in a minute,
                sometimes more (leap seconds, joy!)




Saturday, August 11, 12
A reality check


          • There are not always 60 seconds in a minute,
                sometimes more (leap seconds, joy!)

          •      Not always 24 hours in a day: sometimes more,
                sometimes less—consider DST




Saturday, August 11, 12
Pop Quiz!
Saturday, August 11, 12
Saturday, August 11, 12
• How many days were there in February 1900?




Saturday, August 11, 12
• How many days were there in February 1900?
          • How about February 2000?




Saturday, August 11, 12
• How many days were there in February 1900?
          • How about February 2000?
          • Remember what you know about leap years.




Saturday, August 11, 12
Saturday, August 11, 12
• There were... 28 days in February 1900




Saturday, August 11, 12
• There were... 28 days in February 1900
          • ... and 29 in February 2000




Saturday, August 11, 12
• There were... 28 days in February 1900
          • ... and 29 in February 2000
          • Why? Years that are divisible by 100 are not leap
                years, whereas years divisible by 400 are




Saturday, August 11, 12
Why? How does that affect me? How do
                        I do it right?




Saturday, August 11, 12
Why? How does that affect me? How do
                        I do it right?

          • Variances in Earth’s rotation and axial tilt cause our
                rotation and revolution to be inconsistent




Saturday, August 11, 12
Why? How does that affect me? How do
                        I do it right?

          • Variances in Earth’s rotation and axial tilt cause our
                rotation and revolution to be inconsistent

          • It means that there’s a lot of particulars and edge
                cases for doing date/time math




Saturday, August 11, 12
Why? How does that affect me? How do
                        I do it right?

          • Variances in Earth’s rotation and axial tilt cause our
                rotation and revolution to be inconsistent

          • It means that there’s a lot of particulars and edge
                cases for doing date/time math

          • Currently, NYC observes DST. But the government
                could change that. Certain parts of the US (Indiana,
                Arizona) don't observe


Saturday, August 11, 12
If that wasn’t enough...


          • Consider what you’d do if you were working for
                Indiana Jones and he wanted you to convert dates
                between the Mayan calendar and the Gregorian
                calendar. Or, more likely, the Julian calendar (run cal
                9 1752 and prepare to be surprised) and the
                Gregorian calendar.




Saturday, August 11, 12
How do we handle this?




Saturday, August 11, 12
use DateTime;




Saturday, August 11, 12
use DateTime;


          • DateTime knows about all these edge cases and
                vagaries and handles them for you, intelligently




Saturday, August 11, 12
use DateTime;


          • DateTime knows about all these edge cases and
                vagaries and handles them for you, intelligently

          • It throws exceptions for invalid data, so you can’t
                construct something that shouldn’t exist




Saturday, August 11, 12
A Word about Timezones




Saturday, August 11, 12
A Word about Timezones
          • By default, DateTime objects use the “floating”
                timezone




Saturday, August 11, 12
A Word about Timezones
          • By default, DateTime objects use the “floating”
                timezone

          • This means that it doesn’t take into account any local
                timezone issues like leap years




Saturday, August 11, 12
A Word about Timezones
          • By default, DateTime objects use the “floating”
                timezone

          • This means that it doesn’t take into account any local
                timezone issues like leap years

          • It’s best to specify the timezone when creating a DT
                object, convert to UTC for working with time/dates,
                and then convert to the user’s local timezone for
                display


Saturday, August 11, 12
my $dt = DateTime->now(time_zone =>
             'America/New_York');

             $dt->set_time_zone('UTC');
             $dt->add(months => 3) # leap year!
             # the next day...
             $dt->set_time_zone('Asia/Taipei');




Saturday, August 11, 12
Getting Dat[ae] into DateTime




Saturday, August 11, 12
Getting Dat[ae] into DateTime

          • Several constructors: new, now, from_epoch




Saturday, August 11, 12
Getting Dat[ae] into DateTime

          • Several constructors: new, now, from_epoch
                • The new constructor takes parameters like hour,
                     minute, second, day, month, year




Saturday, August 11, 12
Getting Dat[ae] into DateTime

          • Several constructors: new, now, from_epoch
                • The new constructor takes parameters like hour,
                     minute, second, day, month, year

                • from_epoch takes a named epoch argument



Saturday, August 11, 12
Getting Dat[ae] into DateTime

          • Several constructors: new, now, from_epoch
                • The new constructor takes parameters like hour,
                     minute, second, day, month, year

                • from_epoch takes a named epoch argument
                • All constructors take a time_zone named
                     argument


Saturday, August 11, 12
my $dt = DateTime->now(
     time_zone => 'EST5EDT'
    );
    my $dt = DateTime->from_epoch(
       epoch => 1234567890,
       time_zone => 'America/New_York',
    );
    my $dt = DateTime->new(
       minute => 24,
       hour => 20,
       year => 2012,
       month => 3,
       day => 1
    );

Saturday, August 11, 12
Manipulating Dates




Saturday, August 11, 12
Manipulating Dates
          • Arithmetic operations are overloaded




Saturday, August 11, 12
Manipulating Dates
          • Arithmetic operations are overloaded
          • Subtracting two DateTime objects yields a
                DateTime::Duration (the delta)




Saturday, August 11, 12
Manipulating Dates
          • Arithmetic operations are overloaded
          • Subtracting two DateTime objects yields a
                DateTime::Duration (the delta)

          • Adding two objects doesn't make sense; add
                a ::Duration to get a DateTime object




Saturday, August 11, 12
Manipulating Dates
          • Arithmetic operations are overloaded
          • Subtracting two DateTime objects yields a
                DateTime::Duration (the delta)

          • Adding two objects doesn't make sense; add
                a ::Duration to get a DateTime object

          • See also add, subtract methods (take same args as
                new)


Saturday, August 11, 12
my $later = $dt->clone->add(days => 2);
    my $duration = $later - $dt;
    my $later_also = $dt + $duration;




Saturday, August 11, 12
Getting Dat[ae] Out




Saturday, August 11, 12
Getting Dat[ae] Out

          • DateTime overloads the " operator; this produces an
                ISO8601-formatted string. There are lots of other
                formatters on CPAN, including one for MySQL types.




Saturday, August 11, 12
Getting Dat[ae] Out

          • DateTime overloads the " operator; this produces an
                ISO8601-formatted string. There are lots of other
                formatters on CPAN, including one for MySQL types.

          • There's a strftime method for very flexible
                formatting




Saturday, August 11, 12
Getting Dat[ae] Out

          • DateTime overloads the " operator; this produces an
                ISO8601-formatted string. There are lots of other
                formatters on CPAN, including one for MySQL types.

          • There's a strftime method for very flexible
                formatting

          • Other simpler methods, like ymd, as well as varied
                accessors


Saturday, August 11, 12
my $announcement = "It is now $dt";
             my $proper_date = $dt->strftime(
                "%Y-%m-%d"
             );
             my $identical = $dt->ymd;




Saturday, August 11, 12
Questions?




Saturday, August 11, 12

Más contenido relacionado

Destacado

Giving directions presentation_oseiasa_modelo
Giving directions presentation_oseiasa_modeloGiving directions presentation_oseiasa_modelo
Giving directions presentation_oseiasa_modeloOseias Alves
 
Adjectives describing appearance and personality
Adjectives   describing appearance and personalityAdjectives   describing appearance and personality
Adjectives describing appearance and personalityLjubica Ruzinska
 
Can We Assess Creativity?
Can We Assess Creativity?Can We Assess Creativity?
Can We Assess Creativity?John Spencer
 
Guided Reading: Making the Most of It
Guided Reading: Making the Most of ItGuided Reading: Making the Most of It
Guided Reading: Making the Most of ItJennifer Jones
 

Destacado (8)

Describing people
Describing peopleDescribing people
Describing people
 
Asking and giving direction
Asking and giving directionAsking and giving direction
Asking and giving direction
 
Asking giving directions
Asking giving directionsAsking giving directions
Asking giving directions
 
Giving directions presentation_oseiasa_modelo
Giving directions presentation_oseiasa_modeloGiving directions presentation_oseiasa_modelo
Giving directions presentation_oseiasa_modelo
 
Adjectives describing appearance and personality
Adjectives   describing appearance and personalityAdjectives   describing appearance and personality
Adjectives describing appearance and personality
 
Street directions
Street directionsStreet directions
Street directions
 
Can We Assess Creativity?
Can We Assess Creativity?Can We Assess Creativity?
Can We Assess Creativity?
 
Guided Reading: Making the Most of It
Guided Reading: Making the Most of ItGuided Reading: Making the Most of It
Guided Reading: Making the Most of It
 

Último

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Último (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Date time

  • 1. Dates and Times The Silent Killers Saturday, August 11, 12
  • 2. Dates and Times Are Easy! Saturday, August 11, 12
  • 3. Dates and Times Are Easy! • 60 seconds in a minute, 60 minutes in an hour. Saturday, August 11, 12
  • 4. Dates and Times Are Easy! • 60 seconds in a minute, 60 minutes in an hour. • 24 hours in a day, 365 days in a year, unless the year is a multiple of 4. Saturday, August 11, 12
  • 5. Dates and Times Are Easy! • 60 seconds in a minute, 60 minutes in an hour. • 24 hours in a day, 365 days in a year, unless the year is a multiple of 4. • Simple, right? Saturday, August 11, 12
  • 8. A reality check • There are not always 60 seconds in a minute, sometimes more (leap seconds, joy!) Saturday, August 11, 12
  • 9. A reality check • There are not always 60 seconds in a minute, sometimes more (leap seconds, joy!) • Not always 24 hours in a day: sometimes more, sometimes less—consider DST Saturday, August 11, 12
  • 12. • How many days were there in February 1900? Saturday, August 11, 12
  • 13. • How many days were there in February 1900? • How about February 2000? Saturday, August 11, 12
  • 14. • How many days were there in February 1900? • How about February 2000? • Remember what you know about leap years. Saturday, August 11, 12
  • 16. • There were... 28 days in February 1900 Saturday, August 11, 12
  • 17. • There were... 28 days in February 1900 • ... and 29 in February 2000 Saturday, August 11, 12
  • 18. • There were... 28 days in February 1900 • ... and 29 in February 2000 • Why? Years that are divisible by 100 are not leap years, whereas years divisible by 400 are Saturday, August 11, 12
  • 19. Why? How does that affect me? How do I do it right? Saturday, August 11, 12
  • 20. Why? How does that affect me? How do I do it right? • Variances in Earth’s rotation and axial tilt cause our rotation and revolution to be inconsistent Saturday, August 11, 12
  • 21. Why? How does that affect me? How do I do it right? • Variances in Earth’s rotation and axial tilt cause our rotation and revolution to be inconsistent • It means that there’s a lot of particulars and edge cases for doing date/time math Saturday, August 11, 12
  • 22. Why? How does that affect me? How do I do it right? • Variances in Earth’s rotation and axial tilt cause our rotation and revolution to be inconsistent • It means that there’s a lot of particulars and edge cases for doing date/time math • Currently, NYC observes DST. But the government could change that. Certain parts of the US (Indiana, Arizona) don't observe Saturday, August 11, 12
  • 23. If that wasn’t enough... • Consider what you’d do if you were working for Indiana Jones and he wanted you to convert dates between the Mayan calendar and the Gregorian calendar. Or, more likely, the Julian calendar (run cal 9 1752 and prepare to be surprised) and the Gregorian calendar. Saturday, August 11, 12
  • 24. How do we handle this? Saturday, August 11, 12
  • 26. use DateTime; • DateTime knows about all these edge cases and vagaries and handles them for you, intelligently Saturday, August 11, 12
  • 27. use DateTime; • DateTime knows about all these edge cases and vagaries and handles them for you, intelligently • It throws exceptions for invalid data, so you can’t construct something that shouldn’t exist Saturday, August 11, 12
  • 28. A Word about Timezones Saturday, August 11, 12
  • 29. A Word about Timezones • By default, DateTime objects use the “floating” timezone Saturday, August 11, 12
  • 30. A Word about Timezones • By default, DateTime objects use the “floating” timezone • This means that it doesn’t take into account any local timezone issues like leap years Saturday, August 11, 12
  • 31. A Word about Timezones • By default, DateTime objects use the “floating” timezone • This means that it doesn’t take into account any local timezone issues like leap years • It’s best to specify the timezone when creating a DT object, convert to UTC for working with time/dates, and then convert to the user’s local timezone for display Saturday, August 11, 12
  • 32. my $dt = DateTime->now(time_zone => 'America/New_York'); $dt->set_time_zone('UTC'); $dt->add(months => 3) # leap year! # the next day... $dt->set_time_zone('Asia/Taipei'); Saturday, August 11, 12
  • 33. Getting Dat[ae] into DateTime Saturday, August 11, 12
  • 34. Getting Dat[ae] into DateTime • Several constructors: new, now, from_epoch Saturday, August 11, 12
  • 35. Getting Dat[ae] into DateTime • Several constructors: new, now, from_epoch • The new constructor takes parameters like hour, minute, second, day, month, year Saturday, August 11, 12
  • 36. Getting Dat[ae] into DateTime • Several constructors: new, now, from_epoch • The new constructor takes parameters like hour, minute, second, day, month, year • from_epoch takes a named epoch argument Saturday, August 11, 12
  • 37. Getting Dat[ae] into DateTime • Several constructors: new, now, from_epoch • The new constructor takes parameters like hour, minute, second, day, month, year • from_epoch takes a named epoch argument • All constructors take a time_zone named argument Saturday, August 11, 12
  • 38. my $dt = DateTime->now( time_zone => 'EST5EDT' ); my $dt = DateTime->from_epoch( epoch => 1234567890, time_zone => 'America/New_York', ); my $dt = DateTime->new( minute => 24, hour => 20, year => 2012, month => 3, day => 1 ); Saturday, August 11, 12
  • 40. Manipulating Dates • Arithmetic operations are overloaded Saturday, August 11, 12
  • 41. Manipulating Dates • Arithmetic operations are overloaded • Subtracting two DateTime objects yields a DateTime::Duration (the delta) Saturday, August 11, 12
  • 42. Manipulating Dates • Arithmetic operations are overloaded • Subtracting two DateTime objects yields a DateTime::Duration (the delta) • Adding two objects doesn't make sense; add a ::Duration to get a DateTime object Saturday, August 11, 12
  • 43. Manipulating Dates • Arithmetic operations are overloaded • Subtracting two DateTime objects yields a DateTime::Duration (the delta) • Adding two objects doesn't make sense; add a ::Duration to get a DateTime object • See also add, subtract methods (take same args as new) Saturday, August 11, 12
  • 44. my $later = $dt->clone->add(days => 2); my $duration = $later - $dt; my $later_also = $dt + $duration; Saturday, August 11, 12
  • 46. Getting Dat[ae] Out • DateTime overloads the " operator; this produces an ISO8601-formatted string. There are lots of other formatters on CPAN, including one for MySQL types. Saturday, August 11, 12
  • 47. Getting Dat[ae] Out • DateTime overloads the " operator; this produces an ISO8601-formatted string. There are lots of other formatters on CPAN, including one for MySQL types. • There's a strftime method for very flexible formatting Saturday, August 11, 12
  • 48. Getting Dat[ae] Out • DateTime overloads the " operator; this produces an ISO8601-formatted string. There are lots of other formatters on CPAN, including one for MySQL types. • There's a strftime method for very flexible formatting • Other simpler methods, like ymd, as well as varied accessors Saturday, August 11, 12
  • 49. my $announcement = "It is now $dt"; my $proper_date = $dt->strftime( "%Y-%m-%d" ); my $identical = $dt->ymd; Saturday, August 11, 12