Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get first day of previous month Datetime with Dartlang

Tags:

dart

I want to get first day of previous month in Dart as DateTime. Below code is working correctly even for x = 1 (passing 0 as month)

  print(new DateTime(2016,x-1,1));

but is it by design or I should not relay on it ?

like image 418
tomaszkubacki Avatar asked Nov 22 '16 04:11

tomaszkubacki


1 Answers

It is by design. The DateTime constructor you are using allows overflow and underflow on both days and months. A month value less than one means a month prior to January, which is a month in a previous year. Likewise a day value of less than one is a day in a previous month.

like image 195
lrn Avatar answered Oct 31 '22 00:10

lrn