Skip to content

Commit

Permalink
fix: reimplement convert_to_epoch function
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohan Bansal committed Aug 5, 2024
1 parent e5e8a66 commit 65a8dbe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import datetime
import json
import time
from pytz import timezone
from dateutil.relativedelta import relativedelta
from pytz import UnknownTimeZoneError, timezone

import frappe
from frappe.core.doctype.doctype.doctype import no_value_fields, table_fields
from frappe.model.document import Document
from frappe.query_builder import DocType
from frappe.utils.data import flt, get_datetime, getdate
from frappe.utils.data import flt, get_datetime

from erpnext.controllers.queries import get_fields

Expand Down Expand Up @@ -111,15 +110,23 @@ def applies_to(self, doc):


def convert_to_epoch(date):
system_settings = frappe.get_cached_doc("System Settings", "System Settings")
d = datetime.datetime.now(
timezone(time.tzname if isinstance(time.tzname, (int, str)) else time.tzname[0])
) # or some other local date )
utc_offset = d.utcoffset().total_seconds()
return (
(get_datetime(date) - datetime.timedelta(hours=12, seconds=int(utc_offset)))
- get_datetime("1970-1-1")
).total_seconds()
tzname = time.tzname if isinstance(time.tzname, (int, str)) else time.tzname[0]

try:
tz = timezone(tzname)
except UnknownTimeZoneError:
# default to beginning of epoch
return

d = datetime.datetime.now(tz) # or some other local date
utc_offset = d.utcoffset()
if utc_offset:
utc_offset_seconds = utc_offset.total_seconds()
offset_d = (
get_datetime(date) - datetime.timedelta(hours=12, seconds=int(utc_offset_seconds))
) - get_datetime("1970-01-01")
return offset_d.total_seconds()
return


def convert_from_epoch(date):
Expand Down
13 changes: 3 additions & 10 deletions inventory_tools/tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
# For license information, please see license.txt

import datetime
import types
from itertools import groupby

import frappe
from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
from frappe.utils.data import add_months, flt, getdate, nowdate, get_datetime

from erpnext.accounts.doctype.account.account import update_account_number
from erpnext.manufacturing.doctype.production_plan.production_plan import (
get_items_for_material_requests,
)
from erpnext.setup.utils import enable_all_roles_and_domains, set_defaults_for_tests
from erpnext.stock.get_item_details import get_item_details

from erpnext.setup.utils import set_defaults_for_tests
from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
from frappe.utils.data import add_months, flt, getdate, nowdate, get_datetime
from webshop.webshop.doctype.website_item.website_item import make_website_item

from inventory_tools.tests.fixtures import (
attributes,
boms,
customers,
items,
Expand Down

0 comments on commit 65a8dbe

Please sign in to comment.