fix timezone - time with local timezone to default timezone

This commit is contained in:
pyaephyoeaung
2022-05-19 14:20:55 +06:30
parent 7598a96e60
commit 214712fd2d
48 changed files with 294 additions and 305 deletions

View File

@@ -181,53 +181,47 @@ class Transactions::SalesController < ApplicationController
def get_date_range_from_params
period_type = params[:period_type]
period = params[:period]
from = params[:from]
to = params[:to]
day_ref = Time.now
if from.present? && to.present?
f_date = DateTime.parse(from)
t_date = DateTime.parse(to)
f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
from = f_time.beginning_of_day
to = t_time.end_of_day
else
case period.to_i
when PERIOD["today"]
from = day_ref.beginning_of_day.utc
to = day_ref.end_of_day.utc
if params[:from].present? && params[:to].present?
from = Time.zone.parse(params[:from])
to = Time.zone.parse(params[:to])
else
case period.to_i
when PERIOD["today"]
from = Time.current
to = Time.current
when PERIOD["yesterday"]
from = 1.day.ago
to = 1.day.ago
when PERIOD["this_week"]
from = Time.current.beginning_of_week
to = Time.current
when PERIOD["last_week"]
from = 1.week.ago.beginning_of_week
to = 1.week.ago.end_of_week
when PERIOD["last_7"]
from = 7.day.ago
to = Time.current
when PERIOD["this_month"]
from = Time.current.beginning_of_month
to = Time.current
when PERIOD["last_month"]
from = 1.month.ago.beginning_of_month
to = 1.month.ago.end_of_month
when PERIOD["last_30"]
from = 30.day.ago
to = Time.current
when PERIOD["this_year"]
from = Time.current.beginning_of_year
to = Time.current
when PERIOD["last_year"]
from = 1.year.ago.beginning_of_year
to = 1.year.ago.end_of_year
end
end
when PERIOD["yesterday"]
from = (day_ref - 1.day).beginning_of_day.utc
to = (day_ref - 1.day).end_of_day.utc
when PERIOD["this_week"]
from = Time.now.beginning_of_week.utc
to = Time.now.utc
when PERIOD["last_week"]
from = (day_ref - 7.day).beginning_of_week.utc
to = (day_ref - 7.day).end_of_week.utc
when PERIOD["last_7"]
from = (day_ref - 7.day).utc
to = Time.now.utc
when PERIOD["this_month"]
from = Time.now.beginning_of_month.utc
to = Time.now.utc
when PERIOD["last_month"]
from = (day_ref - 1.month).beginning_of_month.utc
to = (day_ref - 1.month).end_of_month.utc
when PERIOD["last_30"]
from = (day_ref - 30.day).utc
to = Time.now.utc
when PERIOD["this_year"]
from = Time.now.beginning_of_year.utc
to = Time.now.utc
when PERIOD["last_year"]
from = (day_ref - 1.year).beginning_of_year.utc
to = (day_ref - 1.year).end_of_year.utc
end
end
from = from.beginning_of_day
to = to.end_of_day
return from, to
end