Exemplo n.º 1
0
    def test_datetime_with_time_zone(self):
        oldDefaultTimeZone = TimeZone.getDefault()
        try:
            TimeZone.setDefault(TimeZone.getTimeZone("GMT+4"))
            c = tWithDateTimeZCursor(self.context)

            zoneId = ZoneId.of("GMT+2")
            #This is the datetime we will insert
            localDateTime = LocalDateTime.of(2017, Month.DECEMBER, 31, 22, 0,
                                             0)
            zonedDateTime = ZonedDateTime.of(localDateTime, zoneId)
            #This is the datetime we expect the database to receive
            utcDateTime = LocalDateTime.of(2018, Month.JANUARY, 1, 0, 0, 0)

            c.eventDate = zonedDateTime
            c.insert()
            c.clear()

            c.first()

            zoneIdAfterSelect = ZoneId.of("GMT+4")
            self.assertEquals(utcDateTime, c.eventDate.toLocalDateTime())
            self.assertEquals(zoneIdAfterSelect, c.eventDate.getZone())

        finally:
            TimeZone.setDefault(oldDefaultTimeZone)
Exemplo n.º 2
0
	def next( self, last, tz = TimeZone.getDefault() ):
		cal = Calendar.getInstance( tz, Locale.US )
		limit = cal.clone()
		limit.add( Calendar.YEAR, 1 )
		cal.setTime( last )
		cal.add( Calendar.MINUTE, self.wait )
		n = self.findNext( cal, limit )
		if n == None:
			return None
		return n.getTime()
Exemplo n.º 3
0
	def __init__( self, desc, tz = TimeZone.getDefault() ):
		self.id = desc.getString( "id" )
		self.tz = tz
		self.last = None
		self.next = None
		self.scheds = []
		a = desc.getJSONArray( "scheds" )
		for i in range( a.length() ):
			self.scheds.append( Sched( a.getJSONObject( i ) ) )
		self.cmd = desc.getString( "cmd" )
Exemplo n.º 4
0
 def test_date(self):
     self.assertTrue(hasattr(date, "__tojava__"))
     x = date(2007, 1, 3)
     y = x.__tojava__(Date)
     self.assertIsInstance(y, Date)
     # Note that java.sql.Date operates regarding to default timezone, so adjust offset
     off = TimeZone.getDefault().getRawOffset()
     # It's sufficient for the date to fit; we modulo away the time, so this test
     # won't run into TimeZone issues.
     self.assertEqual((y.getTime()+off)//(1000*60*60*24),
             (x - date(1970, 1, 1)).total_seconds()//(60*60*24))
Exemplo n.º 5
0
def convert_to_date(time_val):
    from java.util import TimeZone, Date
    return Date(time_val.date.time - TimeZone.getDefault().getRawOffset())
Exemplo n.º 6
0
	elif o == '-s':
		startlist.append( a )
	elif o == '-k':
		stoplist.append( a )
	elif o == '-h':
		print sys.argv[0] + " [-options]"
		print "\t-h\n\t\tThis"
		print "\t-r\n\t\tRun all pending jobs."
		print "\t-l\n\t\tDump all jobs."
		print "\t-f FILENAME\n\t\tDefault: FILENAME=acroncfg.json"
		print "\t-s ID\n\t\tStart a job."
		print "\t-k ID\n\t\tStop a job."
		quit()

config = loadjson( configfn )
tz = TimeZone.getDefault()
if config.has( "tz" ):
	tz = TimeZone.getTimeZone( config.getString( "tz" ) )
statefn = config.getString( "statefile" )
if os.path.isfile( statefn ):
	states = loadjson( statefn )
else:
	states = JSONObject()
jobsdesc = config.getJSONArray( "jobs" )
jobs = {}
for i in range( jobsdesc.length() ):
	j = Job( jobsdesc.getJSONObject( i ), tz )
	if states.has( j.id ):
		j.setState( states.getJSONObject( j.id ) )
	jobs[j.id] = j
Exemplo n.º 7
0
def convert_to_date(time_val):
    from java.util import TimeZone, Date
    return Date(time_val.date.time - TimeZone.getDefault().getRawOffset())