Skip to content

Commit

Permalink
more robust date formats
Browse files Browse the repository at this point in the history
  • Loading branch information
limenet committed Jun 14, 2017
1 parent 718c7db commit c31cc56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void Form1_Load(object sender, EventArgs e)

private void btnPrint_Click(object sender, EventArgs e)
{
(new PrinterAPI(txtTitle.Text, txtBarcode.Text, timestamp.Value.ToString(), (int)cntCopies.Value)).print();
(new PrinterAPI(txtTitle.Text, txtBarcode.Text, timestamp.Value.ToString("o"), (int)cntCopies.Value)).print();
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
Expand Down
11 changes: 10 additions & 1 deletion PrinterAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ public PrinterAPI(string title, string barcode, string timestamp = null, int cou
{
this.title = title;
this.barcode = barcode;
this.timestamp = timestamp != null ? DateTime.Parse(timestamp).ToString(timestampFormat) : DateTime.Now.ToString(timestampFormat);
this.timestamp = DateTime.Now.ToString(timestampFormat);
if (timestamp != null)
{
try
{
this.timestamp = DateTime.Parse(timestamp).ToString(timestampFormat);
}
finally { }
}

this.count = count;
}

Expand Down

0 comments on commit c31cc56

Please sign in to comment.