~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to test/misc/make_date_test.py

  • Committer: Matt Giuca
  • Date: 2010-07-22 02:12:36 UTC
  • mfrom: (1812.1.13 late-submit)
  • Revision ID: matt.giuca@gmail.com-20100722021236-k8kt4cqdtywzpk24
Merge from trunk late-submit.
Students may now submit projects after the deadline, but they are warned that the submission is late.
Lecturers are now given data on which submissions were made late, and how many days.
(LP: #598346)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# Run in a user's jail to test the "short date format" displayed in the
 
3
# file browser's file table.
 
4
#
 
5
# Generates a bunch of files in the current directory and sets their date
 
6
# stamps to various dates in the past.
 
7
# The files are named after their date stamps relative to today.
 
8
#
 
9
# Author: Matt Giuca
 
10
# Date: 13/1/2008
 
11
 
 
12
import os
 
13
import time
 
14
 
 
15
seconds_per_day = 60*60*24
 
16
time_now = time.time()
 
17
 
 
18
if time.daylight:
 
19
    timezone_offset = time.altzone
 
20
else:
 
21
    timezone_offset = time.timezone
 
22
 
 
23
# Time at the beginning of today, local time
 
24
local_daystart \
 
25
    = time_now - int(time_now - timezone_offset) % seconds_per_day
 
26
 
 
27
def make_file_days_ago(days_ago):
 
28
    global time_now
 
29
    make_file(str(days_ago) + "days",
 
30
        time_now - seconds_per_day*days_ago)
 
31
def make_file(fname, timestamp):
 
32
    f = open(fname, 'w')
 
33
    f.close()
 
34
    os.utime(fname, (timestamp, timestamp))
 
35
 
 
36
make_file_days_ago(0)
 
37
make_file_days_ago(1)
 
38
make_file_days_ago(2)
 
39
make_file_days_ago(3)
 
40
make_file_days_ago(4)
 
41
make_file_days_ago(5)
 
42
make_file_days_ago(6)
 
43
make_file_days_ago(7)
 
44
make_file_days_ago(10)
 
45
make_file_days_ago(365)
 
46
 
 
47
# Now a boundary test - Make a file in the last second of Yesterday.
 
48
make_file("first_second_today", local_daystart)
 
49
make_file("last_second_yesterday", local_daystart-1)