From a8d71f0ac6a659b867aa4d36a25fa9ec222cd72f Mon Sep 17 00:00:00 2001
From: Scott Lahteine <sourcetree@thinkyhead.com>
Date: Wed, 13 Jul 2016 12:57:59 -0700
Subject: [PATCH] Support longer print times in M31

---
 Marlin/Marlin_main.cpp | 20 +++++++++++++++-----
 Marlin/language_en.h   |  7 +++++++
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index e2937c39e3..c5d411cf85 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -3948,12 +3948,22 @@ inline void gcode_M17() {
  */
 inline void gcode_M31() {
   millis_t t = print_job_timer.duration();
-  int min = t / 60, sec = t % 60;
-  char time[30];
-  sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
-  SERIAL_ECHO_START;
-  SERIAL_ECHOLN(time);
+  int d = int(t / 60 / 60 / 24),
+      h = int(t / 60 / 60) % 60,
+      m = int(t / 60) % 60,
+      s = int(t % 60);
+  char time[18];                                          // 123456789012345678
+  if (d)
+    sprintf_P(time, PSTR("%id %ih %im %is"), d, h, m, s); // 99d 23h 59m 59s
+  else
+    sprintf_P(time, PSTR("%ih %im %is"), h, m, s);        // 23h 59m 59s
+
   lcd_setstatus(time);
+
+  SERIAL_ECHO_START;
+  SERIAL_ECHOPGM(MSG_PRINT_TIME " ");
+  SERIAL_ECHOLN(time);
+
   thermalManager.autotempShutdown();
 }
 
diff --git a/Marlin/language_en.h b/Marlin/language_en.h
index ef60220942..eb14505783 100644
--- a/Marlin/language_en.h
+++ b/Marlin/language_en.h
@@ -488,12 +488,18 @@
 #ifndef MSG_PLEASE_RESET
   #define MSG_PLEASE_RESET                    "Please reset"
 #endif
+#ifndef MSG_END_DAY
+  #define MSG_END_DAY                         "days"
+#endif
 #ifndef MSG_END_HOUR
   #define MSG_END_HOUR                        "hours"
 #endif
 #ifndef MSG_END_MINUTE
   #define MSG_END_MINUTE                      "minutes"
 #endif
+#ifndef MSG_PRINT_TIME
+  #define MSG_PRINT_TIME                      "Print time"
+#endif
 #ifndef MSG_HEATING
   #define MSG_HEATING                         "Heating..."
 #endif
@@ -521,6 +527,7 @@
 #ifndef MSG_DELTA_CALIBRATE_CENTER
   #define MSG_DELTA_CALIBRATE_CENTER          "Calibrate Center"
 #endif
+
 #ifndef MSG_INFO_MENU
   #define MSG_INFO_MENU                       "About Printer"
 #endif