@@ -818,4 +818,52 @@ describe('Date object', function()
818818 local end_of_2021 = Date .from_string (' 2021-12-31' )
819819 assert .are .same (' 52' , end_of_2021 :get_week_number ())
820820 end )
821+
822+ it (' should add month correctly | long month + short month' , function ()
823+ local date = Date .from_string (' 2021-05-31' )
824+ assert .are .same (' 2021-05-31 Mon' , date :to_string ())
825+ assert .are .same (' 2021-06-30 Wed' , date :add ({ month = 1 }):to_string ())
826+ end )
827+
828+ it (' should add month correctly | short month + long month' , function ()
829+ local date = Date .from_string (' 2021-04-30' )
830+ assert .are .same (' 2021-04-30 Fri' , date :to_string ())
831+ assert .are .same (' 2021-05-30 Sun' , date :add ({ month = 1 }):to_string ())
832+ end )
833+
834+ it (' should add month correctly | long month + february' , function ()
835+ local date = Date .from_string (' 2021-01-31' )
836+ assert .are .same (' 2021-01-31 Sun' , date :to_string ())
837+ assert .are .same (' 2021-02-28 Sun' , date :add ({ month = 1 }):to_string ())
838+ end )
839+
840+ it (' should add month correctly | long month + february in leap year' , function ()
841+ local date = Date .from_string (' 2024-01-31' )
842+ assert .are .same (' 2024-01-31 Wed' , date :to_string ())
843+ assert .are .same (' 2024-02-29 Thu' , date :add ({ month = 1 }):to_string ())
844+ end )
845+
846+ it (' should calculate end of month correctly | long month' , function ()
847+ local date = Date .from_string (' 2021-05-31' )
848+ assert .are .same (' 2021-05-31 Mon' , date :to_string ())
849+ assert .are .same (' 2021-05-31 Mon' , date :end_of (' month' ):to_string ())
850+ end )
851+
852+ it (' should calculate end of month correctly | short month' , function ()
853+ local date = Date .from_string (' 2021-04-30' )
854+ assert .are .same (' 2021-04-30 Fri' , date :to_string ())
855+ assert .are .same (' 2021-04-30 Fri' , date :end_of (' month' ):to_string ())
856+ end )
857+
858+ it (' should calculate end of month correctly | february' , function ()
859+ local date = Date .from_string (' 2021-02-28' )
860+ assert .are .same (' 2021-02-28 Sun' , date :to_string ())
861+ assert .are .same (' 2021-02-28 Sun' , date :end_of (' month' ):to_string ())
862+ end )
863+
864+ it (' should calculate end of month correctly | february leap-year' , function ()
865+ local date = Date .from_string (' 2024-02-29' )
866+ assert .are .same (' 2024-02-29 Thu' , date :to_string ())
867+ assert .are .same (' 2024-02-29 Thu' , date :end_of (' month' ):to_string ())
868+ end )
821869end )
0 commit comments