summaryrefslogtreecommitdiff
path: root/FS/FS/Record.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2012-06-12 16:34:18 -0700
committerMark Wells <mark@freeside.biz>2012-06-12 16:34:18 -0700
commit41967a7cac39ce2156b9b86436ade82f9a99104e (patch)
tree43cb2ec6d40cac0ed12cbc1b8868ae9a7e7884d5 /FS/FS/Record.pm
parentcc6bedada3c99e3e9ca4748546f3b4ab847c3cba (diff)
suppress all fractions of days in unearned revenue calculation, #13289
Diffstat (limited to 'FS/FS/Record.pm')
-rw-r--r--FS/FS/Record.pm21
1 files changed, 20 insertions, 1 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index dfc2abfc4..a93a10ac6 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -39,6 +39,7 @@ use Tie::IxHash;
@EXPORT_OK = qw(
dbh fields hfields qsearch qsearchs dbdef jsearch
str2time_sql str2time_sql_closing regexp_sql not_regexp_sql concat_sql
+ midnight_sql
);
$DEBUG = 0;
@@ -3030,7 +3031,7 @@ sub not_regexp_sql {
=item concat_sql [ DRIVER_NAME ] ITEMS_ARRAYREF
-Returns the items concatendated based on database type, using "CONCAT()" for
+Returns the items concatenated based on database type, using "CONCAT()" for
mysql and " || " for Pg and other databases.
You can pass an optional driver name such as "Pg", "mysql" or
@@ -3051,6 +3052,24 @@ sub concat_sql {
}
+=item midnight_sql DATE
+
+Returns an SQL expression to convert DATE (a unix timestamp) to midnight
+on that day in the system timezone, using the default driver name.
+
+=cut
+
+sub midnight_sql {
+ my $driver = driver_name;
+ my $expr = shift;
+ if ( $driver =~ /^mysql/i ) {
+ "UNIX_TIMESTAMP(DATE(FROM_UNIXTIME($expr)))";
+ }
+ else {
+ "EXTRACT( EPOCH FROM DATE(TO_TIMESTAMP($expr)) )";
+ }
+}
+
=back
=head1 BUGS