Skip to content
Snippets Groups Projects
Commit a67e15f7 authored by meskio's avatar meskio :tent:
Browse files

Add time to order deadline

parent fbb7315f
No related branches found
No related tags found
No related merge requests found
......@@ -388,8 +388,7 @@ func updateOrderPurchase(tx *gorm.DB, memberNum int, transaction *Transaction, t
func (d *DB) DeactivateOrders() []Order {
var orders []Order
now := time.Now()
t := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
err := d.db.Where("active = ? AND deadline < ?", true, t).
err := d.db.Where("active = ? AND deadline < ?", true, now).
Preload("Member").
Preload("Transactions.OrderPurchase.OrderProduct.Product").
Preload("Transactions.Member").
......
......@@ -200,7 +200,7 @@ func TestOrderNoDeactivation(t *testing.T) {
order := testOrder
now := time.Now()
order.Deadline = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
order.Deadline = now.Add(time.Hour)
resp := tapi.doOrder("POST", "/order", order, nil)
if resp.StatusCode != http.StatusCreated {
t.Fatal("Can't create order:", resp.Status)
......@@ -236,7 +236,7 @@ func TestOrderDeactivation(t *testing.T) {
tapi.addTestProducts()
order := testOrder
order.Deadline = time.Now().Add(-24 * time.Hour)
order.Deadline = time.Now().Add(-1 * time.Minute)
resp := tapi.doOrder("POST", "/order", order, nil)
if resp.StatusCode != http.StatusCreated {
t.Fatal("Can't create order:", resp.Status)
......
......@@ -13,3 +13,4 @@ cicer:
- MAIL_SERVER=
- MAIL_ADDR=
- MAIL_PASS=
- TZ=Europe/Madrid
......@@ -11,7 +11,6 @@ function EditOrder() {
const [order, setOrder] = useState();
const [body, setBody] = useState();
const [sent, setSent] = useState(false);
console.log(body);
if (sent) {
return <Redirect to={"/order/" + id} />;
......
......@@ -2,7 +2,6 @@ import React, { useState } from "react";
import { Form, Row, Col } from "react-bootstrap";
import ProductPicker from "../ProductPicker";
import Fetcher from "../Fetcher";
import { daysAfterNow, date2string } from "../util";
function order2picks(order) {
return order.products.map((p) => {
......@@ -14,6 +13,23 @@ function order2picks(order) {
});
}
function daysAfterNow(days) {
let date = new Date();
date.setDate(date.getDate() + days);
date.setHours(23, 59, 0, 0);
return date;
}
function date2string(date) {
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
return date.toISOString().slice(0, 16);
console.log(date);
console.log(date.toLocaleString());
const zonedDate = new Date(date.toLocaleString());
console.log(zonedDate);
console.log(zonedDate.toISOString().slice(0, 16));
}
function genBody(name, description, deadline, picks) {
const products = picks.map((p) => {
return { code: p.code, price: p.price };
......@@ -49,7 +65,7 @@ function OrderEditor(props) {
};
const setDeadline = (str) => {
_setDeadline(str);
const body = genBody(name, description, deadline, picks);
const body = genBody(name, description, str, picks);
props.onChange(body);
};
const setPicks = (picks) => {
......@@ -136,7 +152,7 @@ function OrderEditor(props) {
</Form.Label>
<Col sm={9}>
<Form.Control
type="date"
type="datetime-local"
value={deadline}
onChange={(e) => setDeadline(e.target.value)}
min={date2string(daysAfterNow(1))}
......
......@@ -184,6 +184,8 @@ class ShowOrder extends React.Component {
}
}
const deadlineStr = printDate(this.state.order.deadline, true);
return (
<Fetcher
url={"/api/order/" + id}
......@@ -197,7 +199,9 @@ class ShowOrder extends React.Component {
</Col>
<Col className="text-right">
<p>
Fecha limite: {printDate(this.state.order.deadline)}
Fecha limite:
<br />
{deadlineStr}
{expired}
</p>
{update_button}
......
......@@ -4,13 +4,7 @@ import icon from "./icon";
import TransactionTr from "./TransactionTr";
import MemberPicker from "../member/MemberPicker";
import Fetcher from "../Fetcher";
import {
printMoney,
printDate,
printTransactionID,
daysAfterNow,
date2string,
} from "../util";
import { printMoney, printDate, printTransactionID } from "../util";
const engType = {
compra: "purchase",
......@@ -19,6 +13,16 @@ const engType = {
devolucion: "refund",
};
function daysAfterNow(days) {
let date = new Date();
date.setDate(date.getDate() + days);
return date;
}
function date2string(date) {
return date.toISOString().split("T")[0];
}
function TransactionList() {
const [transactions, setTransactions] = useState([]);
const [startDate, setStartDate] = useState(date2string(daysAfterNow(-30)));
......
......@@ -2,8 +2,13 @@ function printMoney(money) {
return (money / 100).toFixed(2);
}
function printDate(date) {
return new Date(date).toLocaleDateString();
function printDate(date, time) {
const d = new Date(date);
let dateStr = d.toLocaleDateString();
if (time) {
dateStr += " " + d.toLocaleTimeString();
}
return dateStr;
}
function printRole(role) {
......@@ -29,22 +34,4 @@ function url(path) {
return api + path;
}
function daysAfterNow(days) {
let date = new Date();
date.setDate(date.getDate() + days);
return date;
}
function date2string(date) {
return date.toISOString().split("T")[0];
}
export {
printMoney,
printDate,
printRole,
url,
daysAfterNow,
date2string,
printTransactionID,
};
export { printMoney, printDate, printRole, url, printTransactionID };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment