php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #34932
Patch add-date-quarter-support revision 2013-04-01 15:50 UTC by programming at stefan-koch dot name

Patch add-date-quarter-support for Date/time related Bug #34932

Patch version 2013-04-01 15:50 UTC

Return to Bug #34932 | Download this patch
Patch Revisions:

Developer: programming@stefan-koch.name

From 7eaa0a8d93d2db369dfedcc59f1ac7d03211f2da Mon Sep 17 00:00:00 2001
From: Stefan Koch <taikano@lavabit.com>
Date: Mon, 1 Apr 2013 11:40:26 +0200
Subject: [PATCH] added support for quarter of year in date(), see #34932

---
 ext/date/lib/dow.c  | 5 +++++
 ext/date/php_date.c | 1 +
 2 files changed, 6 insertions(+)

diff --git a/ext/date/lib/dow.c b/ext/date/lib/dow.c
index b6c2d69..bbeb925 100644
--- a/ext/date/lib/dow.c
+++ b/ext/date/lib/dow.c
@@ -140,6 +140,11 @@ timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll
 	return day + ((w - 1) * 7) + d;
 }
 
+timelib_sll timelib_quarter_of_year(timelib_sll m)
+{
+	return (m - 1) / 3 + 1;
+}
+
 int timelib_valid_time(timelib_sll h, timelib_sll i, timelib_sll s)
 {
 	if (h < 0 || h > 23 || i < 0 || i > 59 || s < 0 || s > 59) {
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 4ef3143..0ac0f34 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -1105,6 +1105,7 @@ static char *date_format(char *format, int format_len, timelib_time *t, int loca
 			case 't': length = slprintf(buffer, 32, "%d", (int) timelib_days_in_month(t->y, t->m)); break;
 
 			/* year */
+			case 'Q': length = slprintf(buffer, 32, "%d", (int) timelib_quarter_of_year(t->m)); break;
 			case 'L': length = slprintf(buffer, 32, "%d", timelib_is_leap((int) t->y)); break;
 			case 'y': length = slprintf(buffer, 32, "%02d", (int) t->y % 100); break;
 			case 'Y': length = slprintf(buffer, 32, "%s%04lld", t->y < 0 ? "-" : "", php_date_llabs((timelib_sll) t->y)); break;
-- 
1.8.2

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC